UIControl
组件有 normal
,disabled
和 selected
3 种状态,normal
和 selected
状态下又有 2 种额外的状态 disabled
和 highlighted
状态用来表示被点击时的状态。
所以 state
一共有 6 种有效组合:
normal
默认状态highlighted
被点击状态disabled
禁用交互状态,这个状态下不应该有高亮了selected
已选择状态selected
+highlighted
已选择 + 被点击selected
+disabled
已选择 + 禁止交互,一般用于不可取消的默认选择
在 Swift 种,为 UIButton 设置状态:
let button = UIButton(type: .custom)
button.setTitle("1", for: .normal)
button.setTitle("2", for: .highlighted)
button.setTitle("3", for: .disabled)
button.setTitle("4", for: .selected)
button.setTitle("5", for: [.selected, .highlighted])
button.setTitle("6", for: [.selected, .disabled])