Doo*_*oom 59 iphone checkbox ios
可能重复:
IPhone应用程序中的复选框
我想创建一个带有2个值的简单复选框并保存,我该怎么做?
谢谢.
Gal*_*ank 121
是的,iOS中没有你的复选框( - :
这是我创建复选框的方法:
UIButton *checkbox;
BOOL checkBoxSelected;
checkbox = [[UIButton alloc] initWithFrame:CGRectMake(x,y,20,20)];
// 20x20 is the size of the checkbox that you want
// create 2 images sizes 20x20 , one empty square and
// another of the same square with the checkmark in it
// Create 2 UIImages with these new images, then:
[checkbox setBackgroundImage:[UIImage imageNamed:@"notselectedcheckbox.png"]
forState:UIControlStateNormal];
[checkbox setBackgroundImage:[UIImage imageNamed:@"selectedcheckbox.png"]
forState:UIControlStateSelected];
[checkbox setBackgroundImage:[UIImage imageNamed:@"selectedcheckbox.png"]
forState:UIControlStateHighlighted];
checkbox.adjustsImageWhenHighlighted=YES;
[checkbox addTarget:(nullable id) action:(nonnull SEL) forControlEvents:(UIControlEvents)];
[self.view addSubview:checkbox];
Run Code Online (Sandbox Code Playgroud)
现在在目标方法中执行以下操作:
-(void)checkboxSelected:(id)sender
{
checkBoxSelected = !checkBoxSelected; /* Toggle */
[checkbox setSelected:checkBoxSelected];
}
Run Code Online (Sandbox Code Playgroud)
而已!
Jus*_*Sid 34
在iOS上有切换UI组件而不是复选框,查看UISwitch类.属性on(布尔值)可以用来确定滑块的状态以及状态的保存:这取决于你如何保存其他东西,它只是保存一个布尔值.
| 归档时间: |
|
| 查看次数: |
115196 次 |
| 最近记录: |