0

I'm having trouble setting a gradient as the background to my UINaviagtionBar. I've created a class that handles the CAGradientLayer which seems to be fine until I set the gradient to the navigation bar's layer. The buttons and the title fade away once i start going through the stacks and even going back to the topContorller ("Settings" View) the title becomes faded as well.

At Launch of the UINaviagtionController

Going through the stack

Here is my code I'm running on the "Settings" view

- (void)viewDidLoad {
[super viewDidLoad];

// Do any additional setup after loading the view.

CAGradientLayer * randomLayer = [Gradient gold];

randomLayer.frame = CGRectMake(0, -20, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height + 20);

[randomLayer setStartPoint:CGPointMake(0.0, 0.5)];
[randomLayer setEndPoint:CGPointMake(1.0, 0.5)];

[self.navigationController.navigationBar.layer insertSublayer:randomLayer atIndex:1]; 
}

maybe there's a way to bring the NavigationBarItems to the front of the layer or maybe another approach? I've first came across this one Gradient Background, which seems not to work for me. I'm pretty sure I'm missing a step or over thinking it, appreciate the help in advance

Community
  • 1
  • 1
waffles
  • 37
  • 8
  • It sounds like you may be adding the gradient many times - have you tried making sure its only called once? – sschale Feb 27 '16 at 09:28
  • You write that code may be multiple time for particular navigation controller. – Pramod Tapaniya Feb 27 '16 at 09:31
  • I'm pretty sure, I mean I placed it on viewWillAppear at first and the gradient become darker and darker, an ugly yellow, every time I went back to the settings view which lead me to place it in the viewDidLoad @sschale – waffles Feb 27 '16 at 09:41
  • Am i writing the code for that NavigationController? Yes, I've ran that code in the UINavigationController too, which seem to have failed. @PramodTapaniya – waffles Feb 27 '16 at 09:52
  • @waffles write this code on customnavigationviewcontroller.m file. – Pramod Tapaniya Feb 27 '16 at 09:54
  • I ran the code on viewDidLoad and viewWillAppear in the customNavController.m and to my surprise nothing happened. the NavigationBar is just white now. should i still be getting the NavigationBar like this '[self.navigationController.navigationBar.layer insertSublayer:randomLayer atIndex:1];' ? @PramodTapaniya – waffles Feb 27 '16 at 10:55

0 Answers0