如何在iOS中创建一个简单的复选框? [英] How to create a simple checkbox in iOS?

查看:183
本文介绍了如何在iOS中创建一个简单的复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

IPhone应用程序中的复选框


我想创建一个简单的复选框2值,并保存,我该如何做呢?



谢谢。

解决方案>

是的,在iOs中没有复选框( - :
这里,这是我做了一个复选框

  UIButton * checkbox和
BOOL checkBoxSelected;
checkbox = [[UIButton alloc] initWithFrame:CGRectMake(x,y,20,20)
// 20x20是checckbox你想要的
//创建2个图像大小20x20,一个空方形和
//同一个正方形的另一个带有复选标记
//使用这些新图像创建2个UIImages,然后:

[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 .....]
[self.view addSubview:checkbox];

现在在目标方法中执行以下操作:

   - (void)checkboxSelected:(id)sender 
{
checkBoxSelected =!checkBoxSelected; / * Toggle * /
[checkbox setSelected:checkBoxSelected];
}

这是


Possible Duplicate:
Checkbox in IPhone application

I want to create a simple checkbox with 2 values and save this, how can I make that?

Thanks.

解决方案

Yeah, no checkbox for you in iOs (-: Here, this is what I did to create a checkbox

UIButton *checkbox and
BOOL checkBoxSelected;
checkbox = [[UIButton alloc] initWithFrame:CGRectMake(x,y,20,20)
// 20x20 is the size of the checckbox 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.....]
[self.view addSubview:checkbox];

Now in the target method do the following:

-(void)checkboxSelected:(id)sender
{
    checkBoxSelected = !checkBoxSelected; /* Toggle */
    [checkbox setSelected:checkBoxSelected];
}

that's it

这篇关于如何在iOS中创建一个简单的复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆