1

I've been trying to avoid for loop all day but I can't anymore. Guys, how do I do the following: I have 9 UIButtons called :imageCallerButton1,imageCallerButton2,imageCallerButton3,etc is there a way to change the radius using a for loop instead of adding 18lines?

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

}
Sobiaholic
  • 2,927
  • 9
  • 37
  • 54

2 Answers2

0

You need to create an array or another collection before you can use a for loop:

NSArray *buttons = [NSArray arrayWithObjects: imageCallerButton1, imageCallerButton2, ...];
for (UIButton *btn in buttons) {
    btn.layer.cornerRadius = 10;
    btn.clipsToBounds = YES;
}
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
-1

Try using an array of imageCallerButtons.

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

}
Kalon
  • 111
  • 1
  • 10
  • Your syntax is wrong. `imageCallerButton` is a variable name, not a type. And then you go on and use both `imageCallerButton` and `imgCB` as names for the array--but you appear to be using Java syntax, which is not anything like Objective-C or C syntax when it comes to arrays. – Jonathan Grynspan Aug 15 '12 at 04:02