按钮组中只选中一个的效果

让一个按钮组合实现只有一个按钮被选中,根据所选的按钮初始化不同的试图控制器,



- (void)initInterFace

{

    //按钮名数组

    NSArray * nomalButtonName = [[NSArrayalloc] initWithObjects:@"1_08",@"2_09",@"3_10",@"4_11",nil];

    NSArray * selectedButtonName = [[NSArrayalloc] initWithObjects:@"理财产品_08",@"基金_09",@"贵金属_10",@"保险_11",nil];

    

/*------------标题按钮  -------------*/

    _buttonArray = [[NSMutableArrayalloc] init];

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

       

        UIButton * topButton = [[UIButtonalloc] initWithFrame:CGRectMake(300+i*120,30, 120,38)];

        topButton.tag =8000 + i;

        [topButton setImage:[UIImageimageNamed:nomalButtonName[i]] forState:UIControlStateNormal];

        [topButton setImage:[UIImageimageNamed:selectedButtonName[i]]forState:UIControlStateSelected];

        [topButton addTarget:selfaction:@selector(pressedTopTitleButton:)forControlEvents:UIControlEventTouchUpInside];

        [self.viewaddSubview:topButton];

        [_buttonArrayaddObject:topButton];

    }    

    [selfpressedTopTitleButton:_buttonArray[0]]; //让第一个按钮被选中

}


#pragma mark -点击事件

- (void)pressedTopTitleButton:(UIButton *)sender

{

    //让多个按钮只有一个被选中

   if(sender !=_currentButton){

        

       //打开用户交互

       _currentButton.userInteractionEnabled =YES;

       _currentButton.selected =NO;

        

        [selfinitContentVC:sender.tag]; //根据tag值来决定初始化哪一个控制器

       _currentButton = sender;

    }

   _currentButton.selected =YES;

    _currentButton.userInteractionEnabled =NO;


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值