0
- (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 上显示其他左或右栏按钮项目。

4

1 回答 1

0

哟不应该将图像添加到图像视图并将其添加为子视图。相反,您应该调用setBackgroundImage:forBarMetrics:或使用外观委托来设置导航栏的背景图像。

于 2013-08-18T09:21:31.620 回答