是否可以禁用UISwitch?我的意思不是让它处于关闭状态,我的意思是禁用用户交互,并使其显示为灰色。
在我的应用中,我有两个条件
if (condition == true) {
// UISwitch should be enabled
} else {
// UISwitch should be visible, but disabled
// e.g uiswitch.enable=NO;
} 有什么建议吗?
发布于 2011-04-14 21:49:58
这应该可以做到:
switch.enabled = NO;或者等效地:
[switch setEnabled:NO];其中,switch是您的UISwitch变量名称。
2018年4月18日编辑
上面的答案(显然)是Objective-C解决方案,早在任何人听说过Swift之前就已经写好了。当然,Swift等效的解决方案是:
switch.isEnabled = false
发布于 2011-04-14 21:49:06
是的你可以。UISwitch继承自UIControl,UIControl具有enabled属性。Apple's UIControl Documentation提供了所有的细节。
启用的
switch.enabled = YES;要禁用
switch.enabled = NO;发布于 2017-04-20 03:12:01
对于那些寻找Swift 3的人来说,
switch.isEnabled = false // Disabled switch我知道你没有要求“关闭”状态,但为了防止有人,像我一样,在这里偶然发现:
switch.isOn = falsehttps://stackoverflow.com/questions/5664213
复制相似问题