Search code examples
swiftuibuttontvos

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


I am creating an app for tvOS. I am trying to set the color of an UIButton but does not know how to get I t right.

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.

enter image description here

How do I color the buttons correctly?


Solution

  • buttonA.layer.cornerRadius = 10