Reputation: 9805
I have the following code within my table view controller. It returns a custom view for section headers in the table.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
if (tableView == contentTable && section == 0) {
// When I set backgroundColor to [UIColor redColor] it works. Otherwise white.
[header setBackgroundColor:[UIColor colorWithRed:10.f green:12.f blue:88.f alpha:1.f]];
} else {
[header setBackgroundColor:[UIColor clearColor]];
}
return header;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (tableView == contentTable && section == 0) {
return 30;
}
return 0;
}
Now this code works fine, however the view returned is White. If I ever set the backgroundColor
to [UIColor redColor]
for example it will turn red. However if I set a custom RGB value it will just stay white. I used RGB values from within photoshop.
Upvotes: 0
Views: 503
Reputation: 1881
If you want to use the color values from Photoshop, you can use like
[UIColor colorWithRed:10.f/255.0f green:12.f/255.0f blue:88.f/255.0f alpha:1.0f]];
This is the way I use.
Enjoy yourself!
Upvotes: 0
Reputation: 5343
[header setBackgroundColor:[UIColor colorWithRed:10.0f/255.0 green:12.0f/255.0 blue:88.0f/255.0 alpha:1.f]];
Upvotes: 0
Reputation: 45598
The RGB values are floats whose range must be between 0.0f
and 1.0f
. If you want to convert from 0-255 values, divide each value by 255.0f
.
Upvotes: 3