This is my code, which occurs 48 times (one for each button in a calendar).
calenderButton *a1 = [calenderButton buttonWithType:UIButtonTypeCustom];
[a1 makeFrame:CGRectMake(75, 50, 70, 70) number:1 color:[UIColor orangeColor]];
[self.view addSubview:a1];
What I want to do is put this in a “for loop”, changing the “a1” to “a2”, “a3”, etc, to cut down on the amount of code. I figure I can cut it down to 6 “for loops”.
How do I get the “a1″s to be a variable that I can then reference in not only the code above but in the “for loop”? (the for loop would be something like this:)
for(int i = 0, j=75; i < 7; i++, j+=75);
I know I have to concatenate the “a” with the integer “i”, but how do I place that in the message?
You can put your buttons into an array, like this:
Declare an instance variable
NSMutableArray *allButtonsin your header, then…Now all your buttons are in an array. You can access them by index or in any other way that you may need, e.g. with a fast enumeration loop.