【发布时间】:2017-07-06 09:41:00
【问题描述】:
在我的 Xcode 项目中,我想使用 Swift 更改/设置标签的背景颜色。我怎样才能简单地做到这一点?
我有这个,但它只适用于按钮。
label.backgroundColor = UIColor(red: 0/255, green: 159/255, blue: 184/255, alpha: 1.0)
【问题讨论】:
标签: swift3 label xcode8 background-color
在我的 Xcode 项目中,我想使用 Swift 更改/设置标签的背景颜色。我怎样才能简单地做到这一点?
我有这个,但它只适用于按钮。
label.backgroundColor = UIColor(red: 0/255, green: 159/255, blue: 184/255, alpha: 1.0)
【问题讨论】:
标签: swift3 label xcode8 background-color
为 swift 3 更新:
1]如果你想改变UILabel的背景颜色,那么用下面几行简单的代码:
yourLabelName.backgroundColor = UIColor.green
注意:-你也可以使用不同类型的标准颜色,UIColor.white,UIColor.red...
2]如果要改变UILabel的文字颜色,那么用下面几行简单的代码:
yourLabelName.textColor = UIColor.red
// 享受编码...!
【讨论】:
你可以这样做
label.layer.backgroundColor = UIColor(red: 0/255, green: 159/255, blue: 184/255, alpha: 1.0).cgColor
【讨论】:
SWIFT 4.0/3.0:
<your label name>.backgroundColor = UIColor.green
SWIFT 2.0:
<your label name>.backgroundColor = UIColor.green()
【讨论】:
更改 UILabel 背景颜色:
<your label name>.backgroundColor = UIColor.green
更改 UILabel 文本颜色
<your label name>.textColor = UIColor.green
【讨论】: