rohinb
rohinb

Reputation: 418

iOS - Adding gradient as background to all view controllers

I would like to set the background for all my view controllers as a gradient. Currently, I am running this in the viewDidLoad():

CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[UIColorFromRGB(0x10425E) CGColor], (id)    [UIColorFromRGB(0x487F9D) CGColor], nil];
[self.view.layer insertSublayer:gradient atIndex:0];

How can I do this for all my view controllers without having it to put in every view controller's viewDidLoad()?

Upvotes: 1

Views: 333

Answers (1)

Olga Nesterenko
Olga Nesterenko

Reputation: 1334

Make a UIViewController subclass with this code, than use it as a base class for all your view controllers.

Upvotes: 6

Related Questions