我无法在导航栏(或导航控制器,应用程序顶部)中设置完整图像。左边会留下很小的空间。当我放置信息按钮时,它不在图像上。我该如何解决呢?
这是我的代码,请看看
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];
非常感谢你。
我。
答案 0 :(得分:2)
如果您希望导航栏无法显示图像,请尝试使用
@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
答案 1 :(得分:0)
使用此代码行在导航控制器中添加图像...
UIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerBG.png"]];
img.frame = CGRectMake(0, 0, 320, 44);
[self.navigationController.navigationItem addSubView:img];
[img release];
现在,您在导航中设置图像..