Попробуйте так.
Просто включите его в заголовок, и он будет доступен на протяжении всего проекта.
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
Затем сохраните UIColors в NSMutableArray следующим образом:
NSMutableArray *colorArray=[[NSMutableArray alloc]initWithObjects:RGBCOLOR(107, 252, 0),RGBCOLOR(64, 128, 0),RGBCOLOR(51, 128, 0),RGBCOLOR(47, 128, 0),RGBCOLOR(31, 12, 155),RGBCOLOR(47, 72, 254),RGBCOLOR(86, 0, 255),RGBCOLOR(128, 24, 255),RGBCOLOR(240, 101, 255),RGBCOLOR(240, 45, 128),RGBCOLOR(129, 19, 0),RGBCOLOR(220, 18, 3),RGBCOLOR(236, 82, 9),RGBCOLOR(235, 146, 14),RGBCOLOR(255, 255, 0),RGBCOLOR(128, 64, 0),RGBCOLOR(50, 128, 63),RGBCOLOR(12, 64, 128), RGBCOLOR(102, 102, 255),RGBCOLOR(115, 103, 61),nil];
Теперь отобразите цвета в cellForRowAtIndexPath.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.bgView.backgroundColor = [colorArray objectAtIndex:indexPath.row];
return cell;
}
это решит вашу проблему.