在代码的日子里希望你我同行!

关于在iOS开发过程中如何在多个UIbutton中只能选中一个并且与其他可以UIbutton相互切换-高亮

关于在iOS开发过程中如何在多个UIbutton中只能选中一个并且与其他可以UIbutton相互切换-高亮

**********—————— 创建UIbutton ——————***************

UIButton *alipayButton = [UIButton buttonWithType:UIButtonTypeSystem];
alipayButton.frame = CGRectMake(_fourView.frame.origin.x + 50, xianLabel.frame.origin.y + 1, 90, 64);
[alipayButton setBackgroundImage:[UIImage imageNamed:@"ali_pay.png"] forState:UIControlStateNormal];
alipayButton.tag = 1000000;
[alipayButton addTarget:self action:@selector(payButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[_fourView addSubview:alipayButton];
UIButton *wechatButton = [UIButton buttonWithType:UIButtonTypeSystem];
wechatButton.frame = CGRectMake(_fourView.frame.size.width - 140, alipayButton.frame.origin.y, alipayButton.frame.size.width, alipayButton.frame.size.height);
[wechatButton setBackgroundImage:[UIImage imageNamed:@"wchat_pay.png"] forState:UIControlStateNormal];
wechatButton.tag = 1000001;
[wechatButton addTarget:self action:@selector(payButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[_fourView addSubview:wechatButton];

************——————————实现UIbutton 的相互切换————————————****************

  • (void)payButtonAction:(UIButton *)sender {

    UIButton *alipayButton = [_fourView viewWithTag:1000000];
    UIButton *weChatButton = [_fourView viewWithTag:1000001];
    if (sender.tag == 1000000) {
    [alipayButton setBackgroundImage:[UIImage imageNamed:@"ali_pay_sure"] forState:UIControlStateNormal];
    [weChatButton setBackgroundImage:[UIImage imageNamed:@"wchat_pay"] forState:UIControlStateNormal];
    }else if (sender.tag == 1000001) {
    [weChatButton setBackgroundImage:[UIImage imageNamed:@"wchat_pay_sure"] forState:UIControlStateNormal];
    [alipayButton setBackgroundImage:[UIImage imageNamed:@"ali_pay"] forState:UIControlStateNormal];
    } }

关于在iOS开发过程中如何在多个UIbutton中只能选中一个并且与其他可以UIbutton相互切换-高亮
关于在iOS开发过程中如何在多个UIbutton中只能选中一个并且与其他可以UIbutton相互切换-高亮

发表新评论