iOS 多个按钮,选中其中一个其他按钮不可选
2015-05-21 09:23
99 查看
- (void)layoutUI
{
NSArray *arr = @[@"小桃红",@"桃红",@"橘黄色",@"白色",@"白色紫边",@"粉色",@"紫色",@"红色",@"绿色",@"花边系",@"金黄色",@"黄底红边",@"黄色"];
int k=100;
int l =0;
for (int i = 0; icount/4; i++) {
for (int j = 0; j<<span>4; j++) {
_typeBtn = [[FlowerTypeButtonalloc]initWithFrame:CGRectMake(BOUNDS.origin.x+10 +BOUNDS.size.width/4*j , 5 +40*i, BOUNDS.size.width/4-15, 30)];
_typeBtn.type = arr[l];
[_typeBtnsetTitle:arr[l] forState:UIControlStateNormal];
[_typeBtnsetTitleColor:[UIColorgrayColor] forState:UIControlStateNormal];
[_typeBtnsetTitleColor:[UIColorwhiteColor]forState:UIControlStateSelected];
_typeBtn.titleLabel.font = [UIFontsystemFontOfSize:14.0f];
_typeBtn.layer.cornerRadius = 10.0f;
[_typeBtnsetBackgroundImage:[UIImageimageNamed:@"t_yuan_off"]forState:UIControlStateNormal];
[_typeBtnsetBackgroundImage:[UIImageimageNamed:@"t_yuan_on"]forState:UIControlStateSelected];
[_typeBtnaddTarget:selfaction:@selector(typeBtnAction:)forControlEvents:UIControlEventTouchUpInside];
[self.contentViewaddSubview:_typeBtn];
l ++;
k++;
}
}
}
static BOOL isClickButton;
- (void)typeBtnAction:(FlowerTypeButton *)sender
{
if (_typeBtn == nil)
{
sender.selected = YES;
_typeBtn = sender;
}
else if (_typeBtn !=nil && _typeBtn == sender)
{
sender.selected = YES;
}
else if (_typeBtn!= sender && _typeBtn!=nil)
{
_typeBtn.selected = NO;
sender.selected = YES;
_typeBtn = sender;
}
isClickButton =! isClickButton;
}
注:代码可以直接使用
{
NSArray *arr = @[@"小桃红",@"桃红",@"橘黄色",@"白色",@"白色紫边",@"粉色",@"紫色",@"红色",@"绿色",@"花边系",@"金黄色",@"黄底红边",@"黄色"];
int k=100;
int l =0;
for (int i = 0; icount/4; i++) {
for (int j = 0; j<<span>4; j++) {
_typeBtn = [[FlowerTypeButtonalloc]initWithFrame:CGRectMake(BOUNDS.origin.x+10 +BOUNDS.size.width/4*j , 5 +40*i, BOUNDS.size.width/4-15, 30)];
_typeBtn.type = arr[l];
[_typeBtnsetTitle:arr[l] forState:UIControlStateNormal];
[_typeBtnsetTitleColor:[UIColorgrayColor] forState:UIControlStateNormal];
[_typeBtnsetTitleColor:[UIColorwhiteColor]forState:UIControlStateSelected];
_typeBtn.titleLabel.font = [UIFontsystemFontOfSize:14.0f];
_typeBtn.layer.cornerRadius = 10.0f;
[_typeBtnsetBackgroundImage:[UIImageimageNamed:@"t_yuan_off"]forState:UIControlStateNormal];
[_typeBtnsetBackgroundImage:[UIImageimageNamed:@"t_yuan_on"]forState:UIControlStateSelected];
[_typeBtnaddTarget:selfaction:@selector(typeBtnAction:)forControlEvents:UIControlEventTouchUpInside];
[self.contentViewaddSubview:_typeBtn];
l ++;
k++;
}
}
}
static BOOL isClickButton;
- (void)typeBtnAction:(FlowerTypeButton *)sender
{
if (_typeBtn == nil)
{
sender.selected = YES;
_typeBtn = sender;
}
else if (_typeBtn !=nil && _typeBtn == sender)
{
sender.selected = YES;
}
else if (_typeBtn!= sender && _typeBtn!=nil)
{
_typeBtn.selected = NO;
sender.selected = YES;
_typeBtn = sender;
}
isClickButton =! isClickButton;
}
注:代码可以直接使用
相关文章推荐
- iOS中对于多个按钮,选中其中一个,其他按钮选中状态为NO
- IOS中对于多个按钮,选中其中一个,其他按钮选中状态为NO
- 关于全选按钮和复选框只能选中其中一个的js写法
- iOS 多个按钮选中一个
- iOS 循环创建btn,选中一个,其他的都不选中
- iOS 实现多个按钮,点选一个其它都取消选中状态的最佳方法
- iOS tabbarItem的颜色都是白色,点击其中一个,其他的不变,没有点中的效果
- iOS中button选择其中一个角改变弧度(适用其他控件)
- html,javaScript中怎么控制复选框checkbox的全选,全不选,以及全选中,全选按钮选中,其中一个或者多个没选,则全选按钮不被选中
- 按钮的选中状态(选中一个,其他的变为未选中)
- iOS 证书导出为p12,再导入其他电脑只能导入其中一个的解决方法
- ios中多个按钮只能选中一个
- iOS 实现多个按钮,点选一个其它都取消选中状态的最佳方法
- 给一组单选按钮中的一个指定按钮加上选中标志,并且清除组中其他按钮的选中标志
- html,javaScript中怎么控制复选框checkbox的全选,全不选,以及全选中,全选按钮选中,其中一个或者多个没选,则全选按钮不被选中
- 按钮点击一个,其它都取消选中状态的iOS开发,
- 按钮组,导航条选中其中一个后添加Class突出元素
- js全选,全选以后,如果选中其中一个,全选效果取消,如果复选框全部选中,全选按钮自动也被选中
- iOS 实现多个按钮,点选一个其它都取消选中状态的最佳方法
- 一组按钮,其中一个选中,其余取消选中效果