请注意,这个问题是关于tintColor的。这个问题与backgroundColor无关,这是完全不同的。另外,我注意到有很多关于按钮上图像的色调颜色 的 QA。这与此无关。这是一个关于 .tintColor
UIButton
的问题
有一个典型的(现代)按钮,
private lazy var toggle: UIButton = {
let v = UIButton(type: .custom)
v.configuration = .filled()
v.configuration?.titleTextAttributesTransformer =
UIConfigurationTextAttributesTransformer { i in
var o = i
o.font = UIFont.monospacedSystemFont(ofSize: 12, weight: .medium)
return o
}
v.layer.cornerRadius = 5
v.layer.cornerCurve = .continuous
v.layer.borderWidth = 1
v.layer.borderColor = UIColor.systemYellow.cgColor
v.clipsToBounds = true
v.setTitle("Log", for: [])
v.setTitleColor(.systemGray3, for: [])
v.tintColor = .systemGray
...
请注意,tintColor 是系统灰色。按下按钮时,如何设置tintColor 改变的颜色?
为了更好地表达这一点:当状态改变时,如何(最好使用配置)使tintColor改变为其他指定的颜色?
将配置的
background.backgroundColor
设置为固定颜色,它将保持固定。为了获得更大的灵活性(例如,按下时显示不同的颜色),请设置配置的
background.backgroundColorTransformer
。