0

我试图弄清楚如何将自定义背景图像添加到使用系统图标或图像图标的 NavigationBar 按钮。

我已经想出了如何将背景图像添加到带有文本的 NavigationBar 按钮,但我正在努力弄清楚如何使用图标按钮来实现这一点。

对于我遵循本教程的文本按钮:http: //idevrecipes.com/2010/12/13/wooduinavigation/

如何创建带有图标的自定义按钮?

谢谢!

4

1 回答 1

0

你可能会得到帮助

 @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

这对我来说可以

我们还有另一个想法。

  @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);

} @结尾

于 2011-02-19T08:53:49.640 回答