开发者

Navigation Bar background is hiding right button and cannot remove it on next views

I'm using the category below to programmatically change the navigation bar background into my app. It works fine but I cannot see the right button I added in the nav bar. The button seems hidden as tapping on right side nav bar still trigger the action connected to the nav bar right button. Also, how do I remove the navigation background that was added with the given category method ?

UINavigationBar+CustomImage.h

#import <Foundation/Foundation.h>

@interface UINavigationBar (CustomImage)
  - (void)setBackgroundImage:(UIImage *)image;
  - (void)clearBackgroundImage;

UINavigationBar+CustomImage.m

#import "UINavigationBar+CustomImage.h"

@implementation UINavigationBar (CustomImage)
{
  if(image==nil) return;

  UIImageView *image_view = [[UIImageView alloc] initWithImage:image];
  image_view.frame = CGRectMake(0,0,320,44);
  [self addSubview:image_view];
}

- (void)clearBackgroundImage
{
  NSSArray *subviews = [self subviews];
  for(int i=0;i<[subviews count];i++)
  {
     if([[subviews objectAtIndex:i] isMemberOfClass:[UIImageView class]])
     {
         [[subviews objectAtIndex:i] removeFromSuperview];
     }
  }

}

And in my view controller it's called like this:

[[self.navigationController navigationBar] performSelectorInBackground:@selector(se开发者_StackOverflowtBackgroundImage:) withObject:[UIImage imageNamed:@"header-background.png"]];

Thanks for helping,

Stephane


try sending your view to the back:

[self sendSubviewToBack:image_view];

placing it at a specific z-index:

[self insertSubview:image_view atIndex:0];

or below another view:

[self insertSubview:image_view belowSubview:anotherSubview];

or above another view:

[self insertSubview:image_view aboveSubview:anotherSubview];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜