- (UINavigationController *)navigationController {
nav = [[UINavigationController alloc]
initWithRootViewController:[self demoController]];
UIImage *image;
// If Iphone/iPod Touch
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
// If iPhone 5 or new iPod Touch
if([UIScreen mainScreen].bounds.size.height == 568){
image = [UIImage imageNamed:@"nav.png"];
} else{
// Regular iPhone
image = [UIImage imageNamed:@"nav.png"];
}
}
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[nav.navigationBar addSubview:imageView];
return nav;
}
当我尝试将leftBarButtonItem添加为
- (UIBarButtonItem *)leftMenuBarButtonItem {
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[backButton setBackgroundImage:[UIImage imageNamed:@"main_menu.png"] forState:UIControlStateNormal];
UIBarButtonItem *barBackButtonItem = [[UIBarButtonItem alloc] initWithCustomView: backButton];
[backButton addTarget:self action:@selector(leftSideMenuButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
return barBackButtonItem;
}
它不会在导航上显示 main_menu.png,但如果注释此代码
// [nav.navigationBar addSubview:imageView];
它将显示 main_menu.png,有什么问题,为什么 nav.png 现在显示其他图像,它被添加为子视图,所以我应该怎么做才能在 nav.png 上显示其他左或右栏按钮项目。