我有一系列按钮,我想在所有按钮中更改一些属性。
阵列是这样的:
NSArray *buttons = @[_smallButton, _mediumButton, _largeButton, _xlargeButton];
按钮是插座:
@property (weak, nonatomic) IBOutlet UIButton *smallButton;
@property (weak, nonatomic) IBOutlet UIButton *mediumButton;
@property (weak, nonatomic) IBOutlet UIButton *largeButton;
@property (weak, nonatomic) IBOutlet UIButton *xlargeButton;
现在我想在数组的循环中更改所有borderColor
并为每个设置标记:
for(int i=0; i< buttons.count; i++) {
[buttons[i] layer].borderColor = [UIColor darkGrayColor].CGColor;
[buttons[i] setTag:i];
}
关键是setTag
工作正常并应用于所有按钮,但borderColor
仅针对第一个项目进行更改,而不是全部更改。
有人知道我错过了什么吗?
答案 0 :(得分:2)
尝试为所有人设置borderWidth
和cornerRadius
,即:
for(int i=0; i< buttons.count; i++) {
[buttons[i] layer].borderColor = [UIColor darkGrayColor].CGColor;
[buttons[i] layer].borderWidth = 1;
[buttons[i] layer].cornerRadius = 4;
[buttons[i] setTag:i];
}