简体   繁体   English

如何在Swift中为tvOS设置UIButton类型的颜色:.system

[英]How to set color of UIButton type: .system for tvOS in Swift

I am creating an app for tvOS. 我正在为tvOS创建一个应用程序。 I am trying to set the color of an UIButton but does not know how to get I t right. 我正在尝试设置UIButton的颜色,但不知道如何正确设置。

var buttonA: UIButton(type: .system)
var buttonB: UIButton(type: .system)
...
buttonA.backgroundColor = UIColor.green
buttonB.backgroundColor = UIColor.red

I am happy with the result when the button is in focus but when the button is not in focus I get an ugly result. 当按钮处于焦点位置时,我对结果感到满意,但是当按钮没有处于焦点处时,我会得到一个丑陋的结果。 The green button has a colored layer that is missing its cornerRadius. 绿色按钮的彩色图层缺少其cornerRadius。

在此处输入图片说明

How do I color the buttons correctly? 如何正确给按钮上色?

buttonA.layer.cornerRadius = 10

These values are not customizable in instances of UIButton for tvOS out of the box. 在开箱即用的tvOS的UIButton实例中,无法自定义这些值。 You have to create your custom solution in order to have your custom layout. 您必须创建自定义解决方案才能拥有自定义布局。

You can take a look to the implementation of this component for further details https://github.com/dcordero/FocusTvButton 您可以查看此组件的实现以获取更多详细信息https://github.com/dcordero/FocusTvButton

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM