ios - 如何在 iOS 中创建复选框?
<p><p>我采用了两个自定义按钮和一种方法来设置它们的选中和取消选中</p>
<p>在 viewdidload() 中我是这样写的..</p>
<pre><code> forState:UIControlStateNormal];
forState:UIControlStateNormal];
isChecked_01 = NO; //declared as boolean to change check and uncheck for button one
isChecked_02 = NO; //declared as boolean to change check and uncheck for button two
</code></pre>
<p>在方法中</p>
<pre><code>-(IBAction)checkboxOnClick:(UIButton *)sender {
if (sender.tag == 1) {
if (isChecked_01 == NO) {
forState:UIControlStateNormal];
isChecked_01 = YES;
}
else
{
forState:UIControlStateNormal];
isChecked_01 = NO;
}
}
if (sender.tag == 2) {
if (isChecked_02 == NO) {
forState:UIControlStateNormal];
isChecked_02 = YES;
}
else
{
forState:UIControlStateNormal];
isChecked_02 = NO;
}
}
}
</code></pre>
<p>还有其他方法可以在 ios.. 中创建复选框吗?我已经为每个复选框使用了一个 isCheckedbool 值。是否有可能对整个检查列表只使用一个 bool 值.....</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可以使用 <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIControl_Class/index.html#//apple_ref/occ/instp/UIControl/selected" rel="noreferrer noopener nofollow">selected</a>属性(继承自 UIControl)而不是您的 isChecked_01 和 isChecked_02:</p>
<pre><code> forState:UIControlStateNormal];
forState:UIControlStateNormal];
forState:UIControlStateSelected];
forState:UIControlStateSelected];
- (IBAction)checkboxOnClick:(UIButton *)sender {
sender.selected = !sender.selected;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在 iOS 中创建复选框?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/29974554/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/29974554/
</a>
</p>
页:
[1]