我无法在导航栏(或应用程序顶部的导航 Controller )中设置完整图像。左边几乎没有剩余空间。当我放置信息按钮时,它不在图像上。我该如何解决

这是我的代码,请看一下

UIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerBG.png"]];
    img.frame = CGRectMake(0, 0, 320, 44);
    self.navigationItem.titleView =img;
    [img release];


UIButton * infoDarkButtonType = [[UIButton buttonWithType:UIButtonTypeInfoLight] retain];
     infoDarkButtonType.frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
     infoDarkButtonType.backgroundColor = [UIColor clearColor];
     [infoDarkButtonType addTarget:self action:@selector(showInfo) forControlEvents:UIControlEventTouchUpInside];
     UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithCustomView:infoDarkButtonType];
     self.navigationItem.leftBarButtonItem = infoButton;
     [infoDarkButtonType release];
     [infoButton release];

非常感谢。

我。

最佳答案

如果你想让导航栏显示图像,你可以试试这个

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect
{
  UIImage *image = [UIImage imageNamed: @"custom_nav_bar.png"];
  [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

关于iphone - 无法在导航栏中设置完整图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5945972/

10-13 03:51