Search code examples
iosuitableviewfontsios7

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


Solution

  • 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.