按钮边框颜色 - Objective C - Swift

4

我希望将我的边框颜色更改为一个特定的十六进制颜色(#21CE99),你们能帮帮我吗?

我已经知道如何将其更改为基本颜色,例如:

_button.layer.borderColor = [UIColor greenColor].CGColor;

但是我只需要这种颜色。

谢谢。

答案

如何在Swift中以编程方式设置UIView的自定义边框颜色

3个回答

4

对于使用 SWIFT 4 的人来说,正确答案应该是:

_button.layer.borderColor = UIColor(red: 33/255, green: 206/255, blue: 153/255, alpha: 1.0).cgColor

内置的UIColor预设或您自己的颜色:

_button.layer.borderColor = UIColor.blue.cgColor

2
_button.layer.borderColor = [UIColor colorWithRed:33.0 / 255.0 green:206.0 / 255.0 blue:153.0 / 255.0 alpha:1.0].CGColor;

1
更容易
_button.layer.borderColor = [UIColor colorWithRed:0x21 / 255.0 green:0xce / 255.0 blue:0x99 / 255.0 alpha:1.0].CGColor;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接