1

i have a navigation bar, i want to change it using image, i was implement this code

self.navBar.layer.contents = (id)[UIImage imageNamed:@"flower.png"].CGImage;

but the background is still didn't change. the hierarchy of navigation bar are : - UINavigationBar - UINavigationItem - UISegementControl

i already set an outlet in every part in that hierarchy.. is there something wrong???

R. Dewi
  • 4,141
  • 9
  • 41
  • 66

1 Answers1

1

Here's what I've used quite succesfully:

CALayer *backgroundImageLayer;
backgroundImageLayer = [CALayer layer];
backgroundImageLayer.frame = CGRectMake(0, 0, 300, 44);
backgroundImageLayer.backgroundColor = [UIColor redColor].CGColor;
backgroundImageLayer.contents = (id)[[UIImage imageNamed:@"barImage.png"] CGImage];
backgroundImageLayer.zPosition = -5.0;
[myNavigationConroller.navigationBar.layer addSublayer:test];

The key was setting the zPosition to -5.0, although any negative value should work. It causes the backgroundImageLayer not to interfere with UINavigationBar's buttons and label.

Bartosz Ciechanowski
  • 10,293
  • 5
  • 45
  • 60