ios中多个按钮只能选中一个

来源:互联网 发布:什么矩阵可以lu分解 编辑:程序博客网 时间:2024/06/05 14:09


 //_normalarray = @[@"like",@"More",@"Reply",@"share"];

 _normalarray = [NSArrayarrayWithObjects:@"脑炎后遗症",@"More",@"Reply",@"share",nil];

 _selectedarray =@[@"矮小症",@"矮小症",@"矮小症",@"矮小症"];

 for (int i =0; i < 4; i++) {

  _btntwo = [[UIButtonalloc]initWithFrame:CGRectMake( i *(80 +2),100, 120, 120)];

  _btntwo.backgroundColor = [UIColorredColor];

  [_btntwoaddTarget:selfaction:@selector(clickbtntwo:)forControlEvents:UIControlEventTouchUpInside];

  [_btntwosetBackgroundImage:[UIImageimageNamed:_normalarray[i]]forState:UIControlStateNormal];

  _btntwo.tag = i+100;

  _btntwo.selected =NO;

  _btntwo.layer.cornerRadius =60;

  _btntwo.layer.masksToBounds =YES;

  [_btntwosetBackgroundImage:[UIImageimageNamed:_selectedarray[i]]forState:UIControlStateSelected];

  [self.viewaddSubview:_btntwo];

 }

}


-(void)clickbtntwo:(UIButton *)sender{

 for (int i =0; i < _normalarray.count; i++) {

  UIButton *btn = (UIButton *)[[sendersuperview]viewWithTag:100 + i];

  [btn setSelected:NO];

 }

 UIButton *button = (UIButton *)sender;

 [button setSelected:YES];

}


原创粉丝点击