iOS 按钮单选

@property(nonatomic,strong)NSMutableArray* Btnarray;


  NSArray * titleArray = @[@",@"",@"",@""];

    CGFloat  Start_X =15.0f;// 第一个按钮的X坐标

    CGFloat  Start_Y =140.0f;// 第一个按钮的Y坐标

    CGFloat  Width_Space =15.0f;// 2个按钮之间的横间距

    CGFloat  Button_Height =35.0f;//  高

    CGFloat  Button_Width = (SCREEN_WIDTH-75)/4;// 宽

    _Btnarray = [NSMutableArray array];


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

        NSIntegerindex = i %4;

        // 圆角按钮

        UIButton*TypeButton = [[UIButtonalloc]init];

        TypeButton.tag= i+100;//这句话不写等于废了

        TypeButton.frame=CGRectMake(index * (Button_Width + Width_Space) + Start_X,  Start_Y, Button_Width, Button_Height);

        [TypeButtonsetTitle:titleArray[i]forState:UIControlStateNormal];

        [TypeButtonsetTitleColor:RGBCOLOR(148, 148, 148) forState:UIControlStateNormal];

        TypeButton.layer.borderColor=RGBCOLOR(148,148,148).CGColor;

        TypeButton.titleLabel.font= [UIFontsystemFontOfSize:14];

        TypeButton.layer.borderWidth=1;

        TypeButton.layer.cornerRadius=3;

        [selfaddSubview:TypeButton];

        //按钮点击方法

        [TypeButtonaddTarget:self action:@selector(TypeButtonClick:) forControlEvents:UIControlEventTouchUpInside];

        [_BtnarrayaddObject:TypeButton];

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

    [self.delegate ChooseFRtypeAction:sender];

    for(UIButton*btn1in_Btnarray){

        if(btn1.tag== sender.tag){

            [btn1setTitleColor:RGBCOLOR(79, 139, 244) forState:UIControlStateNormal];

            btn1.layer.borderColor=RGBCOLOR(79,139,244).CGColor;

        }else{

            [btn1setTitleColor:RGBCOLOR(148, 148, 148) forState:UIControlStateNormal];

            btn1.layer.borderColor=RGBCOLOR(148,148,148).CGColor;

        }

    }

}

你可能感兴趣的:(iOS 按钮单选)