一个按钮选中,其余按钮没有选中

 NSArray *wenziAr = [NSArray arrayWithObjects:@"贵金属",@"原油",@"现货",@"股指", @"外汇",nil];

    for(inti =0; i <5; i++) {

        _forBtn= [[UIButtonalloc]initWithFrame:CGRectMake(i*btnwidth,5, btnwidth,32)];

        [_forBtn setTitle:wenziAr[i] forState:UIControlStateNormal];

        //_forBtn.backgroundColor = [UIColor purpleColor];

        _forBtn.tag= i+100;


        [_forBtn addTarget:self action:@selector(clickforBtn:) forControlEvents:UIControlEventTouchUpInside];


        [forViewaddSubview:_forBtn];

        [_forBtn setTitleColor:[UIColor colorWithRed:122.0/255 green:121.0/255 blue:121.0/255 alpha:1] forState:UIControlStateNormal];

        _forBtn.selected=NO;

        [_forBtn setTitleColor:[UIColor colorWithRed:178.0/255 green:17.0/255 blue:25.0/255 alpha:1] forState:UIControlStateSelected];

    }


    returnview;

}

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


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

        //[btn setSelected:NO];

        //UIButton *btn = (UIButton *)[[sender superview]viewWithTag:100 + i];

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

        [btnsetSelected:NO];


        btn.layer.borderWidth=0.0f;

    }

    UIButton*button = (UIButton*)sender;

    [buttonsetSelected:YES];

    button.layer.masksToBounds = YES;

    button.layer.cornerRadius = 15.0f;

    button.layer.borderWidth = 1.0f;

    //button.layer.borderColor = [UIColor colorWithRed:178 green:17 blue:25 a.0/255lpha:<#(CGFloat)#>];

    //button.layer.borderColor = [UIColor colorWithRed:178.0/255 green:17.0/255 blue:25.0/255 alpha:1].CGColor;

    button.layer.borderColor = [UIColor colorWithRed:178.0/255 green:17.0/255 blue:25.0/255 alpha:1].CGColor;

你可能感兴趣的:(一个按钮选中,其余按钮没有选中)