iPhone iOS UILabel how to customize text color for UITableView detail text labels only?
I'm working on an interface prototype and am using a storyboard to do so. Part of the prototype involves setting the detail UILabel for UITableView cells to a certain color. I would like to avoid having to manually recolor every label within a storyboard.
I found that I can use:
[[UILabel appearanceWhenContainedIn:[UITableViewCell class], nil] setTextColor:[UIColor cyanColor]];
To change the appearance of labels within tableview cells. Is there a way to further refine this code to only apply to detail tableview labels? Currently it changes both textLabel and detailTextLabel of UITableViewCell.
You could trick around this by subclassing the cells in the detail view, then use
[[UILabel appearanceWhenContainedIn:[YOUR_UITableViewCell class], nil] setTextColor:[UIColor other_colr]];
If you want to keep using the appearance proxy, you will have to create a custom table view cell and a new label.
- In the storyboard editor you set the style property of your UITableCell to "custom".
- Drag two label to the table view cell and configure it like you want it.
- Create a new class that inherits from UITableViewCell and make IBOutlets for every label.
- In the storyboard editor you set the class of the table view cell to the table view cell class you just created. Connect the outlets to the labels. Actually this is enough, because you can configure the appearance of the cells in the storyboard as well. If you want to configure the label through code you have to execute the following steps as well.
- Create a new class that inherits from UILabel and leave it as is.
- Go back to the storyboard editor and select the detailtextlabel and change the class to the label class you just create.
If you want more information on how to create your own table view cells see Table View Programming Guide for IOS