我UIButton
中有16 UIViewController
,而且一次只需要selected
。
我创建了一个UIButton
集合,并通过执行backgroundColor
来更改for loop
。它工作正常。
但是我需要一两行的快速解决方案,或者我可以说一次点击改变颜色的有效方法。
我认为我的方式不高效,因为如果UIViewController
有50 UIButton
该怎么办。
P.S。不要告诉我采取UICollectionView
,因为我可以很容易地做到这一点!
答案 0 :(得分:1)
无论如何,你需要枚举你的按钮。但你可以在扩展中执行此操作一次:
extension Array where Element: UIButton {
func setBackgroundColor(color: UIColor) {
for element in self {
element.backgroundColor = color
}
}
}