1

for loop一整天都在试图避免,但我再也做不到了。伙计们,我该怎么做:我有 9 个UIButtons叫 : imageCallerButton1imageCallerButton2imageCallerButton3,etc没有办法使用 for 循环而不是添加 18 行来更改半径?

for (int i =9; i<=9; ++i) {
    imageCallerButton1.layer.cornerRadius = 10;
    imageCallerButton1.clipsToBounds = YES;

}
4

2 回答 2

0

您需要先创建一个数组或另一个集合,然后才能使用for循环:

NSArray *buttons = [NSArray arrayWithObjects: imageCallerButton1, imageCallerButton2, ...];
for (UIButton *btn in buttons) {
    btn.layer.cornerRadius = 10;
    btn.clipsToBounds = YES;
}
于 2012-08-15T03:35:35.430 回答
-1

尝试使用 imageCallerButtons 数组。

imgCB = new imageCallerButton [9];
for(int i = 0; i < imgCB.length; i++){
   imageCallerButton[i].layer.cornerRadius = 10;
    imageCallerButton[i].clipsToBounds = YES;

}
于 2012-08-15T03:33:44.777 回答