开发者

Custom navigation bar buttons with system icons and images

I'm trying to figure out how to add a custom background image to NavigationBar buttons that use system icons, or im开发者_运维百科age icons.

I've figured out how to add a background image to NavigationBar buttons with text, but I'm struggling to figure out how to accomplish this with icon buttons.

For the text buttons I followed this tutorial: http://idevrecipes.com/2010/12/13/wooduinavigation/

How can I create custom buttons w/ icons?

Thanks!


u might get help with this

 @implementation UINavigationBar (UINavigationBarCategory)
  -(void)setBackgroundImage:(UIImage*)image{
if(!image) return;
UIImageView *aTabBarBackground = [[UIImageView alloc]initWithImage:image];
//  aTabBarBackground.frame = CGRectMake(0,0,self.frame.size.width,self.frame.size.height);
aTabBarBackground.frame = CGRectMake(0,0,self.frame.size.width * .6,self.frame.size.height);

// [self addSubview:aTabBarBackground];
// [self sendSubviewToBack:aTabBarBackground];
[self insertSubview: aTabBarBackground atIndex: 0];
[aTabBarBackground release];
   }
   @end

it works fine for me

also we hav another idea.

  @implementation UINavigationBar (UINavigationBarCategory)

 - (void)drawRect:(CGRect)rect {
// Drawing code 
UIImage *img = [UIImage imageNamed: @"navbar_background.png"];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, CGRectMake(0, 0, 320, self.frame.size.height), img.CGImage);

} @end

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜