English 中文(简体)
如何检查Box被点击
原标题:How to check a checkBox has been clicked

I am trying to make a menu using checkboxes, which i have created programmatically. Heres how i made my checkBox:

UIButton* checkBox = [[UIButton alloc] initWithFrame:CGRectMake(60,60,300, 44)]; 
[checkBox setImage:[UIImage imageNamed:@"unmarked.png"] forState:UIControlStateNormal];
[checkBox addTarget:self action:@selector(toggleButton:) forControlEvents: UIControlEventTouchUpInside];
[checkBox setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[self.view addSubview:checkBox];

具体目标:

- (void)toggleButton: (id) sender
{
    checkboxSelected = !checkboxSelected;
    UIButton* check = (UIButton*) sender;
    if (checkboxSelected == NO)
        [check setImage:[UIImage imageNamed:@"unmarked.png"] forState:UIControlStateNormal];
    else
        [check setImage:[UIImage imageNamed:@"marked.png"] forState:UIControlStateNormal];

}

现在,我正在做一个简单的习俗:UIButton,我想检查检查检查箱是否使用这一习俗()和NS Carlo是否使用同一条。 如果对Box进行检查,然后在纽顿点点点击,那么,如果国家行车监督记录仪表查,就会发现Box。

谁能帮助我这样做?

任何帮助都将得到真正赞赏。

感谢您的时间

Shailesh

最佳回答

You should consider to use UISwitch, because checkboxes are not that nice on apple mobile devices. You can refer to a tutorial, e.g. here: http://www.xprogress.com/post-30-uiswitch-tutorial-example-how-to-use-the-switch-in-xcode-for-iphone-sample-included/

or here for doing it programatically: Creating a UISwitch Programmatically

Nevertheless, if you insist to use checkboxes look here: How to create a simple checkbox in iOS?

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签