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 に答える