我想在导航栏中更改背景图片。在我的代码下面
UINavigationBar *navBar = self.navigationController.navigationBar;
UIImageView *image1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
image1.image = [UIImage imageNamed:@"image2_ram.jpg"];
[navBar setBackgroundImage:image1.image forBarMetrics:UIBarMetricsDefault];
图像被更改但图像的高度没有改变为什么?
答案 0 :(得分:2)
如果你正在考虑iOS 4.0,你不应该这样设置
使用此
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"bgTopBar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
或iOS 5
使用此功能,无需为其提供框架,并且您无法将高度更改为44以上,导航栏的默认高度为 44
UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:@"bgTopBar.png"];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];