Adding Gradient background to NSViewController CocoaTouch

236 Views Asked by At

I have created a NSViewController which i have called "GradientViewController" with nib file, I have initialised the view and it is getting displayed over my rootViewController. I am wanting to add a gradient background to "GradientViewController". Does anyone know how i can do this?

if I create a CAGradientLayer with "GradientViewController" using

NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:[NSColor orangeColor] endingColor:[NSColor lightGrayColor]];

How would i get this to display? (If it's the correct way to create a gradient)

It's been very difficult to find the answer to this and i've been searching for days. Example code would be great as I am new to cocoaTouch and trying to swap from iOS

1

There are 1 best solutions below

0
On

I always just add a custom view class as a subview and put the gradient in the drawRect function of that when I want gradients on my ViewControllers.