遍历 Objective-C 中的 UIButton 数组

Loop over an array of UIButtons in Objective-C

我有一组按钮,我想更改所有按钮的一些属性。

数组是这样的:

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 仅针对第一个项目进行了更改,而不是所有按钮。

有人知道我错过了什么吗?

尝试为所有这些设置 borderWidthcornerRadius,即:

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];
}