让一个按钮组合实现只有一个按钮被选中,根据所选的按钮初始化不同的试图控制器,
- (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;
}