As far as I know, there's no way to "number" your pointer variable names at runtime.
There are two things you can do, though. First is to use an array. Instead of trying to number your buttons' pointers, put them into an NSMutableArray and reference their "numbers" that way.
Code:
self.starBtnArray = [NSMutableArray arrayWithCapacity:5]; //starBtnArray should be a "retain" NSMutableArray property!
for(i=0;i<5;i++){
StarButton *starBtn = [[StarButton alloc] init];
[starBtnArray addObject:starBtn];
starBtn.tag = i; //For good measure
[starBtn release]; //Bring retain count back down to 1
}
Code:
for(int i=0;i<sender.tag;i++){
[[starBtnArray objectAtIndex:i] setBackgroundImage:coloredStar forState:UIControlStateNormal];
}
Make sure you learn about properties if you don't already understand them...they're very important for objective-C coding. Also make sure you note the change to 0 in the first part of the for loop expressions in the second bit of code, since array indices start at 0.
The second way is to use UIView's viewWithTag: method which returns a view's subview that has the tag.
Code:
for(int i=1;i<sender.tag;i++){ //I'm assuming this is in your view controller?
[[self.view viewWithTag:i] setBackgroundImage:coloredStar forState:UIControlStateNormal];
}
I wouldn't personally prefer this way because then you have to manage and remember to call release for 5 pointers (one for each button) instead of just one (an NSMutableArray). In addition, you can run into trouble if you try to have more than one view with a tag number from 1-5 as viewWithTag only returns one UIView.
It's up to you though, whichever you're more comfortable with.