开发者

navigation bar background did not change

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

self.navBar.laye开发者_StackOverflow中文版r.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???


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜