两个按钮之间的切换(单选)

来源:互联网 发布:js解析jsonarray数据 编辑:程序博客网 时间:2024/06/05 14:35

//添加投诉建议的类型(投诉、建议)

- (void)addRepareType

{

    NSArray *titleArr = @[@"投诉", @"建议"];

    int x = kLeftPadding;

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

        _complaints = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        _complaints.frame = CGRectMake(x, 10, ([UIScreen mainScreen].bounds.size.width - (kLeftPadding * 3))/2, 44);

        _complaints.layer.cornerRadius = 5.0;

        _complaints.layer.borderWidth = 0.5;

        _complaints.layer.masksToBounds = YES;

        _complaints.layer.borderColor = [UIColor colorFromHexRGB:@"f57a19"].CGColor;

        

        [_complaints setTitle:[titleArr objectAtIndex:i] forState:UIControlStateNormal];

        

        [_complaints addTarget:self action:@selector(tapReport:) forControlEvents:UIControlEventTouchUpInside];

        _complaints.titleLabel.font = [UIFont systemFontOfSize:15];

        [_backView addSubview:_complaints];


        _complaints.tag = 200 + i;

        if (_complaints.tag == 200) {

            _complaints.backgroundColor = [UIColor colorFromHexRGB:@"f57a19"];

            [_complaints setTitleColor:[UIColor colorFromHexRGB:@"ffffff"] forState:UIControlStateNormal];

        }if (_complaints.tag == 201) {

            _complaints.backgroundColor = [UIColor colorFromHexRGB:@"ffffff"];

            [_complaints setTitleColor:[UIColor colorFromHexRGB:@"f57a19"] forState:UIControlStateNormal];

        }


        x += ([UIScreen mainScreen].bounds.size.width - (kLeftPadding * 3))/2 + kLeftPadding;

    }

}

//button的点击方法(切换按钮)

- (void)tapReport:(UIButton *)btu

{

    UIButton *btn1 = (UIButton *)[self.view viewWithTag:200];

    UIButton *btn2 = (UIButton *)[self.view viewWithTag:201];

    if (btu.tag == 200) {//个人报修

        btn2.backgroundColor = [UIColor colorFromHexRGB:@"ffffff"];

        [btn2 setTitleColor:[UIColor colorFromHexRGB:@"f57a19"] forState:UIControlStateNormal];

        btn1.backgroundColor = [UIColor colorFromHexRGB:@"f57a19"];

        [btn1 setTitleColor:[UIColor colorFromHexRGB:@"ffffff"] forState:UIControlStateNormal];

        _type = 1;

        NSLog(@"-----type=%d", _type);

        

    }else{//公共报修

        btn1.backgroundColor = [UIColor colorFromHexRGB:@"ffffff"];

        [btn1 setTitleColor:[UIColor colorFromHexRGB:@"f57a19"] forState:UIControlStateNormal];

        btn2.backgroundColor = [UIColor colorFromHexRGB:@"f57a19"];

        [btn2 setTitleColor:[UIColor colorFromHexRGB:@"ffffff"] forState:UIControlStateNormal];

        _type = 5;

        NSLog(@"-----type=%d", _type);

    }


}


0 0
原创粉丝点击