Search code examples
iosuiappearance

iOS: Change appearance of UIView only (no subclasses) - possible?


I have a project with many view controllers, and I want all of them to have parent views with a tiled background image. Now I could do

[[UIView appearance] setBackgroundColor:
    [UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundPattern"]]];

The problem is, this will also set background of all other UIView subclassing objects (UIButtons, UILabels, etc.). What can I do to just change the UIView background?


Solution

  • If you use the appearance proxy at a class level there's no choice. You're going to modify every UIView subclass.

    I don't see many other options to subclassing UIViewController, changing the appearence of that subclass' view only and then making all the others UIViewController subclass of the first one.