Change the background color of immediate subview of UIViewController using UIAppearence

766 views Asked by At

I want to change the background color of all the UIViewController views. I have several UIViewController classes in my project and i want to set the same background of all views once using UIAppearence.

I tried the following code:

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

but it change the background color of every UIView including (UIButton, UIView subclasses and UILabels etc.)

Is there any way to handle this situation, so that i can only change the background color of UIViewController views? I googles a lot but i didn't find any relevent solution.

Any help would be highly appreciated.

Thanks..

1

There are 1 answers

3
oiledCode On

Well I think the best is to subclass UIViewController and in viewDidLoad set the backgroundColor. But if you want to use UIAppearance you can do something like this :

id proxy = [UIView appearanceWhenContainedIn:[UIViewController class],nil];
[proxy setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundImage"]]