导航器工作不正常(Navigation Controller not working properl

2019-09-17 02:18发布

我用我的当前应用程序导航控制器,但是我已经和与iOS4的和iOS5的导航控制器的问题,所以我试着写两个的iOS 4和5的代码

if([[UINavigationBar class] respondsToSelector:@selector(appearance)]) //iOS >=5.0
{
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
else
{
    self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed:@"header.png"].CGImage;
}

但问题是,当我在iOS 4版本上运行我的应用我的导航控制器这个样子的。

请给我建议。

Answer 1:

UINavigationController *navControl;

在其他部分,尝试这样的。

UINavigationBar *navBar = self.navControl.navigationBar;
   UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
            imgView.image = [UIImage imageNamed:@"header.png"];
            [navBar addSubview:imgView];
            [imgView release];


Answer 2:

经过长时间的搜寻我想这个代码,帮我谢谢之后。

进口“ImageViewController.h”

@implementation UINavigationBar (CustomImage)

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

@end
implement this code in your .m file


@implementation ImageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    UIImageView *backGroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
    [self.navigationController.navigationBar insertSubview:backGroundView atIndex:0];
    [backGroundView release];
}

@end


文章来源: Navigation Controller not working properly