0

我正在尝试UINavigationBar使用以下代码自定义项目:

    CGSize size = [UIImage imageNamed:kGlobalNavigationBarButtonBackOrange].size;
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
    [backButton setImage:[UIImage imageNamed:kGlobalNavigationBarButtonBackOrange] forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:kGlobalNavigationBarButtonBackPressedOrange] forState:UIControlStateHighlighted];
    [backButton addTarget:self action:@selector(dismissViewController) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];

    UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Detail"];
    [item setLeftBarButtonItem:barButton];
    [item setTitleView:self.navigationItem.titleView];

    [self.navigationBar pushNavigationItem:item animated:YES];
    [self.navigationController pushViewController:vc animated:YES]; 

但是,当我运行它时,导航栏看起来并没有什么不同。

4

1 回答 1

1

您尝试做的事情应该在您的vc视图控制器中完成。关键在于,当一个新的视图控制器被压入堆栈时,它会被要求提供其导航项,并用于更新导航栏。

- viewDidLoad您的视图控制器中,创建条形按钮并将其设置为self. navigationItem. leftBarButtonItem.

您不需要创建新的导航项或将任何导航项推送到导航栏上。让视图控制器框架为你做这件事。

于 2013-05-06T15:05:45.150 回答