- (void)brandHistoryButton
{
buttonsArray = [[NSMutableArray alloc]init]; //将button放到数组里面
for (int i=0; i<6; i++) {
UIButton *button = [[UIButton alloc]init];
button.frame = CGRectMake(93, 219+(i*46), 103, 35);
// button.backgroundColor = [UIColor blackColor];
[button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"BrandButton%02d",i+1]] forState:UIControlStateNormal];
[button addTarget:self action:@selector(BrandHistoryBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i+200;
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"huang_line"]];
imageView.frame = CGRectMake(0, CGRectGetMaxY(button.frame), CGRectGetWidth(self.LeftBrandView.frame), imageView.image.size.height/2);
[self.LeftBrandView addSubview:button];
[self.LeftBrandView addSubview:imageView];
[buttonsArray addObject:button];
// NSLog(@"-o-o-%f %f-o-o-",imageView.frame.origin.y,imageView.frame.size.height);
}
((UIButton *)[buttonsArray objectAtIndex:0]).selected=YES; // 关键是这里,设置 数组的第一个button为选中状态
NSLog(@"%@",buttonsArray);
UIImageView *iconImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"guomu"]];
iconImageView.frame = CGRectMake(28, 576, iconImageView.image.size.width, iconImageView.image.size.height);
[self.LeftBrandView addSubview:iconImageView];
}
- (void)ButtonState:(UIButton *)button
{
if (_tmpBtn == nil){
button.selected = YES;
_tmpBtn = button;
}
else if (_tmpBtn !=nil && _tmpBtn == button){
button.selected = YES;
}
else if (_tmpBtn!= button && _tmpBtn!=nil){
_tmpBtn.selected = NO;
button.selected = YES;
_tmpBtn = button;
}
}
- (void)BrandHistoryBtnEvent:(UIButton *)button
{
((UIButton *)[buttonsArray objectAtIndex:0]).selected=NO;
[self ButtonState:button];
switch (button.tag) {
case 200:
NSLog(@"200");
self.RightBrandView.hidden = NO;
[self moveLeftView];
break;
case 201:
NSLog(@"201");
self.RightBrandView.hidden = YES;
[self moveLeftView];
break;
case 202:
NSLog(@"202");
[self moveLeftView];
break;
case 203:
NSLog(@"203");
[self moveLeftView];
break;
case 204:
NSLog(@"204");
[self moveLeftView];
break;
case 205:
NSLog(@"205");
[self moveLeftView];
break;
}
if (_tmpBtn.selected == YES) {
[self buttonMark];
}
}