這可能禁用UISwitch?我不是說把它置於關閉狀態,我的意思是禁用用戶交互,並使其顯示爲灰色。如何禁用UISwitch?
在我的應用我有兩個條件
if (condition == true) {
// UISwitch should be enabled
} else {
// UISwitch should be visible, but disabled
// e.g uiswitch.enable=NO;
}
有什麼建議?
這可能禁用UISwitch?我不是說把它置於關閉狀態,我的意思是禁用用戶交互,並使其顯示爲灰色。如何禁用UISwitch?
在我的應用我有兩個條件
if (condition == true) {
// UISwitch should be enabled
} else {
// UISwitch should be visible, but disabled
// e.g uiswitch.enable=NO;
}
有什麼建議?
這應做到:
switch.enabled = NO;
或等價:
[switch setEnabled:NO];
其中switch
是無論你的UISwitch
變量名是。
[switchName enabled] = NO;
使用它來禁用您的開關。
編輯感謝rckoenes:「你不應該嘗試通過getter來設置一個屬性,你應該使用.res語句屬性的setter。」
是的,你可以。 UISwitch
繼承自UIControl
,並且UIControl
具有enabled
屬性。 Apple's UIControl Documentation有所有的細節。
要使
switch.enabled = YES;
要禁用
switch.enabled = NO;
對於那些尋找斯威夫特3,
switch.isEnabled = false // Disabled switch
我知道你沒有問「關閉」狀態,但以防萬一有人像我一樣,偶然發現這裏:
switch.isOn = false
感謝提示 – Pooja 2011-04-14 13:50:47
你不應該嘗試通過getter來設置屬性。你應該使用任何一個setter。語法屬性。 – rckoenes 2011-04-14 13:52:09
不好意思,另外一件事學到了^^ – Joetjah 2011-04-14 14:19:22