在Objective-C中的UIButton数组上循环
我有一个按钮数组,我想改变其中的一些属性 数组如下所示:在Objective-C中的UIButton数组上循环,objective-c,arrays,uibutton,nsarray,layer,Objective C,Arrays,Uibutton,Nsarray,Layer,我有一个按钮数组,我想改变其中的一些属性 数组如下所示: NSArray *buttons = @[_smallButton, _mediumButton, _largeButton, _xlargeButton]; 按钮是: @property (weak, nonatomic) IBOutlet UIButton *smallButton; @property (weak, nonatomic) IBOutlet UIButton *mediumButton; @property (wea
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
s,并在数组上的循环中为每个设置标记:
for(int i=0; i< buttons.count; i++) {
[buttons[i] layer].borderColor = [UIColor darkGrayColor].CGColor;
[buttons[i] setTag:i];
}
for(int i=0;i
关键是setTag
工作正常,可应用于所有按钮,但borderColor
仅针对第一项更改,而不是所有按钮
有人知道我遗漏了什么吗?尝试将
边框宽度
和拐角半径
设置为所有这些参数,即:
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];
}
for(int i=0;i
尝试将边框宽度
和拐角半径
设置为所有这些参数,即:
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];
}
for(int i=0;i
哦,这是一个非常严重的错误,问题是borderWidth,我在情节提要中设置了第一个按钮borderWidth,但忘记设置其余按钮,谢谢。哦,这是一个非常严重的错误,问题是borderWidth,我在情节提要中设置了第一个按钮borderWidth,但忘了设置其余按钮borderWidth,谢谢。