This is more of a math question but I’m just not having any luck. Basically Ive got the code below to change cell colors depending on their row equivalent in the colors array. It all works very well but I would like it so that I could somehow cut off the bottom end of the brightness spectrum so that I never end up with anything say, below 0.2. Any suggestions on how to solve this would be appreciated.
-(IBAction)reloadTable {
float arrayCount = [masterListArray count];
float increment = (1.0 / arrayCount);
NSMutableArray *tempColor = [[NSMutableArray alloc]init];
colors = [[NSMutableArray alloc]init];
for (float brightness = 0.0; brightness < 1.0; brightness += increment) {
UIColor *color = [UIColor colorWithHue:50.0f/255.0f
saturation:1.0
brightness:brightness
alpha:1.0];
[tempColor addObject:color];
NSLog(@"brightness: %f", brightness);
}
colors = [[tempColor reverseObjectEnumerator] allObjects];
[self.tableView reloadData];
}
You can use some extra variables to make sure you always end up between 1.0 and the bottom end. In the below code we use the number of cells to iterate through (better practice than what you had before) and start with brightness 1.0 and end at your bottom end. Also no need to use tempColors.