objective-cuitableviewios9uiappearance

UIAppearance has no effect on Label text color


I am setting the text color of all the labels in my app using UIAppearance. Yet the text color does not change.

Here is a sample of how i create the label

//show the loading message
MessageLabel *messageLabel = [[MessageLabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
messageLabel.text = @"\n\nLoading ...\n\n";
messageLabel.numberOfLines = 0;
messageLabel.textAlignment = NSTextAlignmentCenter;
[messageLabel sizeToFit];
self.tableview.backgroundView = messageLabel;

Here is how i set the text color

[[MessageLabel appearance] setTextColor:[UIColor blackColor]];

One note is that all these MessageLabel are BackgroundViews of UITableView


Solution

  • Referring to this, UIAppearance kind of doesn't really seem work with UILabel...

    Since you're subclassing from UILabel, maybe it would make sense to set textcolor property initWithFrame: method on in your MessageLabel class?

    Or another option, since you say these MessageLabel instances are used for UITableViewCell's background, maybe it would make sense to leave label's background clear and change background of cell itself, for example in tableView:willDisplayCell:forRowAtIndexPath: method in tableView's delegate?