我有以下 UIBarButton 项:
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 100.0f, 45.0f, 30.0f)];
[backButton setBackgroundImage:backButtonImage forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchDown];
backButton.titleLabel.text = @"Back";
backButton.titleLabel.font = [UIFont fontWithName:@"texgyreadventor-regular.otf" size:20.0f];
backButton.titleLabel.textColor = [UIColor whiteColor];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
_backItem = backItem;
在其他一些方法中,我将其设置在导航栏上,如下所示:
[self.navigationItem setLeftBarButtonItem:_backItem];
到目前为止,一切都按预期工作。但就在我将它添加到顶部的导航栏之前,我想更改它的文本。这是我尝试做的一件事:
self.navigationItem.leftBarButtonItem.title = @"NEW TITLE";
然而,这不起作用。如何在运行时动态添加标题?