I have a viewController in my iOS class and in viewDidLoad, I create a gradient with CAGradient and add it to the layer of my view. I want this to appear in other views too, so what's the best way to do that? (New to objective-c and ios, I know how to do this in PHP and C#).
closed as off-topic by Bryan Chen, Abizern, EdChum, Flow, Jeremy Smyth Sep 15 '13 at 13:37This question appears to be off-topic. The users who voted to close gave this specific reason:
|
|||||||||||||||||
|
One way would be to make a category on CALayer, and add a method to create and add your custom gradient. Something like this:
And you could use it like this:
|
|||
|
The easiest way would be to make a base class that all your other view controllers that you want the gradient on inherit from. Just do what you are doing in viewDidLoad in the base class. One thing to remember, if you override viewDidLoad in any of the subclasses, don't forget to call |
|||
|
There's no Objective-C specific way to solve this. You should be able to pull across solutions from other languages. My personal recommendation would be to pull the From here, it depends on how where the view is reused. If you have several different view controllers that all use the same gradient in the same position, then you can make a If you're using the same gradient in myriad places across your app, I would typically add a class method to a I would strongly recommend against rdelmar's solution because it is a) stateful and b) not flexible. That method doesn't give you a pointer to the |
|||||
|