Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 487
user3083408 Avatar asked Dec 09 '22 10:12

user3083408


2 Answers

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.

like image 198
Gavin Avatar answered Dec 11 '22 08:12

Gavin


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;
} 

Let me know if this helped you.

like image 41
Rinat Khanov Avatar answered Dec 11 '22 09:12

Rinat Khanov