我有一个 UIViewController
子类。我在 viewDidLoad
中给 View Controller 一个 rightBarButtonItem,如下所示:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Difficulty"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
当用户按下 View 中的另一个按钮时,UIBarButtonItem
的标题/文本将更改如下:
self.navigationItem.rightBarButtonItem.title = @"Mellansvår";
可以正常使用,但是当标题更改时,它看起来不太好。文字有点跳跃。
我以前在运行时更改过 UILabel
文本,当我更改它们的文本时看起来不像这样,但我不知道如何添加 UILabel
到 navigationItem。我无法在 Interface Builder 中执行此操作,因为导航栏来自 UINavigationController
。
有没有办法更顺利的改标题?
最佳答案
无需再次设置标题,您可以使用标题再次设置按钮,然后为其设置动画:
(void)setRightBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated
关于ios - 更改 UIBarButtonItem 标题时,过渡不稳定/闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23307907/