ObjectiveC UISwitch将默认设置为OFF

时间:2013-06-01 10:49:17

标签: objective-c uiswitch

如何将UISwitch对象的默认值设置为Off?我可能遗漏了一些明显的东西?

3 个答案:

答案 0 :(得分:15)

正如mmccomb和Bruno Koga所提到的,这可以通过编程方式完成。在这种情况下,虽然 - 假设您的UISwitch正在从笔尖解压缩 - 在Interface Builder中简单配置UISwitch可能更方便。

要执行此操作,请打开开关所在的xib,选择开关并打开属性检查器(†),然后在“开关”部分中,将“状态”的值从“开”更改为“关” :

Change the UISwitch's state from On to Off.


†要打开属性检查器,首先按下Xcode工具栏最右侧“视图”分段控件中的右端项目(“实用程序”)

Depress the Utilites item in the View segmented control.

“工具区”出现后,“检查器”窗格位于“库”窗格上方,并从“检查器”选择器栏中选择“属性检查器”项

Select the Attributes Inspector item from the Inspector selector bar.

所有这些术语都来自Apple's Xcode documentation的这张图片。

Xcode 4 workspace.

答案 1 :(得分:1)

假设您有UISwitch的引用,则可以简单地覆盖控制器上的-viewDidLoad方法:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [yourSwitch setOn:NO animated:NO];
}

答案 2 :(得分:0)

使用setOn:animated:method ...

- (void)setOn:(BOOL)on animated:(BOOL)animated

e.g。

[someSwitch setOn:NO animated:YES];

UISwitch Documentation

相关问题