我无法在导航栏(或导航控制器,应用程序顶部)中设置完整图像.左边会留下很小的空间.当我放置信息按钮时,它不在图像上.我该如何解决呢?
这是我的代码,请看看
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