Objective c 是否使用ForLoop方法为9UI按钮指定属性?
我一整天都在努力避免Objective c 是否使用ForLoop方法为9UI按钮指定属性?,objective-c,xcode,Objective C,Xcode,我一整天都在努力避免for loop,但我再也做不到了。伙计们,我该怎么做:我有9个ui按钮叫做:imageCallerButton1,imageCallerButton2,imageCallerButton3等有没有办法用for循环来改变半径,而不是增加18行 for (int i =9; i<=9; ++i) { imageCallerButton1.layer.cornerRadius = 10; imageCallerButton1.clipsToBounds =
for loop
,但我再也做不到了。伙计们,我该怎么做:我有9个ui按钮
叫做:imageCallerButton1
,imageCallerButton2
,imageCallerButton3等
有没有办法用for循环来改变半径,而不是增加18行
for (int i =9; i<=9; ++i) {
imageCallerButton1.layer.cornerRadius = 10;
imageCallerButton1.clipsToBounds = YES;
}
for(int i=9;i尝试使用imageCallerButtons数组
imgCB = new imageCallerButton [9];
for(int i = 0; i < imgCB.length; i++){
imageCallerButton[i].layer.cornerRadius = 10;
imageCallerButton[i].clipsToBounds = YES;
}
imgCB=newimagecallerbutton[9];
for(int i=0;i
您需要创建一个数组或另一个集合,然后才能将用于
循环:
NSArray *buttons = [NSArray arrayWithObjects: imageCallerButton1, imageCallerButton2, ...];
for (UIButton *btn in buttons) {
btn.layer.cornerRadius = 10;
btn.clipsToBounds = YES;
}
非常好的方法!如果我想使用int[I]?@iMohammad你可以使用[buttons objectAtIndex:I]
。我想你的意思是UIButton*
:)@jonathangrynpan是的,没错。非常感谢你!你的语法错了imageCallerButton
是变量名,而不是类型。然后您继续使用imageCallerButton
和imgCB
作为数组的名称——但您似乎使用了Java语法,这与数组的Objective-C或C语法完全不同。