IPhone iOS UILabel, how to adjust text color for UITableView text labels only?

I am working on a prototype interface and use the storyboard for this. Part of the prototype involves setting the UILabel element for the UITableView to a specific color. I would like to avoid having to manually repaint each tag in the storyboard.

I found that I can use:

[[UILabel appearanceWhenContainedIn:[UITableViewCell class], nil] setTextColor:[UIColor cyanColor]]; 

Change the appearance of labels in table cells. Is there a way to further refine this code, applicable only to tabular view labels? It currently modifies both textLabel and detailTextLabel UITableViewCell.

Thanks!

+2
source share
3 answers

You can trick this by subclassing cells in the detail view, then use

 [[UILabel appearanceWhenContainedIn:[YOUR_UITableViewCell class], nil] setTextColor:[UIColor other_colr]]; 
+4
source

If you want to use the appearance proxy, you will need 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 labels into the table view cell and adjust them the way you want it.
  • Create a new class that inherits from UITableViewCell and make IBOutlets for each label.
  • In the storyboard editor, you set the table view cell class to the class of the table view cell that you just created. Connect the sockets to the labels. This is actually enough, because you can also customize the appearance of the cells in the storyboard. If you want to customize the label using code, you also need to follow these steps.
  • Create a new class that inherits UILabel and leave it as it is.
  • Go back to the storyboard editor and select the detailtextlabel and change the class to the label class you just created.

If you need more information on how to create your own table view cells, see Table Programming Guide for iOS

0
source
 [cell.detailTextLabel setTextColor:[UIColor redColor]]; 
-3
source

Source: https://habr.com/ru/post/1238038/


All Articles