iOS应用程序的复选框控件
iOS应用程序的对象库中是否有复选框控件?我最近看到的是开关控件,它可以接受布尔值 您可以使用UIButton的选定状态,为不同设置不同的图像(或文本)(通过代码或界面生成器): 在内部行动的润色中:iOS应用程序的复选框控件,ios,cocoa-touch,checkbox,controls,Ios,Cocoa Touch,Checkbox,Controls,iOS应用程序的对象库中是否有复选框控件?我最近看到的是开关控件,它可以接受布尔值 您可以使用UIButton的选定状态,为不同设置不同的图像(或文本)(通过代码或界面生成器): 在内部行动的润色中: - (IBAction)buttonTouched:(id)sender { button.selected = !button.selected; // add other logic } 这是我用于屏幕上两个复选框的代码。我把它们放在屏幕上的两张图片的底部。我用UIContr
- (IBAction)buttonTouched:(id)sender
{
button.selected = !button.selected;
// add other logic
}
这是我用于屏幕上两个复选框的代码。我把它们放在屏幕上的两张图片的底部。我用UIControlEventTouchDown来调用CycBox的方法。这个方法与我的主视图控制器对话,在这里我决定答案是正确的还是不正确的。然后主视图控制器调用这个视图并告诉它将空白文本框更改为C。见鬼: 还是一个x
// Put the Checkboxes on the screen
UIImage *checkBox = [UIImage imageNamed:@"Checkbox"];
self.checkBoxLeft = [UIButton buttonWithType:UIButtonTypeCustom];
[self.checkBoxLeft setImage:checkBox forState:UIControlStateNormal];
[self.checkBoxLeft setFrame:checkBoxFrameLeft];
[self.checkBoxLeft addTarget:self
action:@selector(checkBoxTapped:)
forControlEvents:UIControlEventTouchDown];
[self.checkBoxLeft setTitle:@"checkBoxLeft" forState:UIControlStateNormal];
self.checkBoxLeft.contentEdgeInsets = insets;
self.checkBoxLeft.showsTouchWhenHighlighted = NO; // Keeps it from turning gray
self.checkBoxRight = [UIButton buttonWithType:UIButtonTypeCustom];
[self.checkBoxRight setImage:checkBox forState:UIControlStateNormal];
[self.checkBoxRight setFrame:checkBoxFrameRight];
[self.checkBoxRight addTarget:self
action:@selector(checkBoxTapped:)
forControlEvents:UIControlEventTouchDown];
[self.checkBoxRight setTitle:@"checkBoxRight" forState:UIControlStateNormal];
self.checkBoxRight.contentEdgeInsets = insets;
self.checkBoxRight.showsTouchWhenHighlighted = NO; // Keeps it from turning gray
- (void)checkBoxTapped:(UIButton *)buttonPressed {
[[self delegate] checkBoxTapped:buttonPressed.currentTitle];
}
- (void)highlightCheckbox:(NSString *)checkboxToHighlight withHighlight:(NSString *)highlight {
if ( [checkboxToHighlight isEqualToString:@"left"] ){
[self.checkBoxLeft setImage:[UIImage imageNamed:highlight] forState:UIControlStateNormal];
} else {
[self.checkBoxRight setImage:[UIImage imageNamed:highlight] forState:UIControlStateNormal];
}
}
//定义按钮的属性 声明未选中的图像
- (void)viewDidLoad
{
[_checkboxButton setBackgroundImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];
}
选中的图像
- (IBAction)buttonTapped:(id)sender
{
if (_checkboxButton.selected == YES)
{
[_checkboxButton setBackgroundImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateSelected];
_checkboxButton.selected = NO;
}
else
{
[_checkboxButton setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
_checkboxButton.selected = YES;
}
}
UISegmentedControl可能对您有所帮助否复选框或单选按钮没有默认的UI控件,在这里,您必须使用两种不同的图像进行选中和未选中,并使用UIButton状态进行逻辑控制以进行选中/取消选中标记。将取消选中(正常状态)和选中(选定状态)的图像放入.Related:这是一个开源库,为它提供了实现。Anirudha-您可以设置背景图像,这可能是您所说的“不工作”。图像是按钮上的图像,与标签一样。背景图像通常用于更改整个按钮。
- (IBAction)buttonTapped:(id)sender
{
if (_checkboxButton.selected == YES)
{
[_checkboxButton setBackgroundImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateSelected];
_checkboxButton.selected = NO;
}
else
{
[_checkboxButton setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
_checkboxButton.selected = YES;
}
}