user3083408
user3083408

Reputation: 335

iOS 7 change UITableViewCell font color to blue like in Settings app

I have a UITableview in grouped style and there is one cell that I want to use like a button. My problem is, the font color of this cell is by default black. I want to have the same blue as font color as the cells used as buttons in the settings app (e.g. in settings/safari the delete history cell is used as a button and has this light iOS 7 styled blue as font color). I would love it if anybody could help me. Much love, Timm

Upvotes: 4

Views: 7692

Answers (2)

Rinat Khanov
Rinat Khanov

Reputation: 1576

You can use this line of code in your cellForRowAtIndexPath method to set up UITableViewCell's font color:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // (cell creation)...
    
    // set to the color that Apple uses
    cell.textLabel.textColor = [UIColor colorWithRed:0.204 green:0.459 blue:1.000 alpha:1.0];
    return cell;
} 

Upvotes: 3

Gavin
Gavin

Reputation: 8200

If you're using a storyboard or xib and you have a prototype cell, go in to it and select the label. Then you can set the color of the text.

If you want to do it programmatically, add the following to your tableView:cellForRowAtIndexPath: method:

cell.textLabel.textColor = [UIColor blueColor];

blueColor isn't exactly the same as the blue used by buttons in iOS 7, but you could manually pick a color that closely approximates it if you wanted instead.

EDIT:

This will give you the exact color you want:

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
cell.textLabel.textColor = [button titleColorForState:UIControlStateNormal];

It's getting the color from a UIButton.

Upvotes: 11

Related Questions