一、创建多个按钮
for (int i = 0 ; i < 13; i++){
NSInteger index = i % 3;
NSInteger page = i / 3;
oneButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
oneButton.frame = CGRectMake(index * (Button_Width + Width_Space), page * (Button_Height + Height_Space), Button_Width, Button_Height);
[oneButton addTarget:self action:@selector(clickButtonSender:) forControlEvents:UIControlEventTouchUpInside];
// [oneButton setTitle:self.fenLeiArray[i] forState:UIControlStateNormal];
[oneButton setTitle:@"哈哈" forState:UIControlStateNormal];
[oneButton setTitleColor:LTTextBlackColor forState:UIControlStateNormal];
oneButton.titleLabel.font = LTFont(14);
oneButton.layer.borderWidth = 1;
oneButton.layer.cornerRadius = 3.0f;
oneButton.layer.borderColor = LTTextGrayColor.CGColor;
oneButton.tag = i;
[self.fenLeiArray addObject:oneButton];
[circleFenLeiView addSubview:oneButton];
}
self.circleFenLeiView.height = 200;
fenLeiViewHieht = self.circleFenLeiView.height;
二、点击事件
// 点击按钮选中
-(void)clickButtonSender:(UIButton *)btn{
[self.view endEditing:YES];
NSLog(@"点击了%ld",btn.tag+1);
classifyStr = btn.titleLabel.text;
NSLog(@"=-=-=-=-=-=-=%@",classifyStr);
for (UIButton *button in self.fenLeiArray) {
if (button.tag == btn.tag) {
button.layer.borderColor = LTRedColor.CGColor;
[button setTitleColor:LTRedColor forState:UIControlStateNormal];
}else{
[button setTitleColor:LTTextBlackColor forState:UIControlStateNormal];
button.layer.borderColor = LTTextGrayColor.CGColor;
}
}
}
网友评论