更改UIBarButtonItem标题时,转换是生涩/闪烁 [英] When changing UIBarButtonItem title, the transition is jerky/flickers

查看:73
本文介绍了更改UIBarButtonItem标题时,转换是生涩/闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIViewController 子类。我在 viewDidLoad 中给视图控制器一个 rightBarButtonItem ,如下所示:

I have a UIViewController subclass. I give the view controller a rightBarButtonItem in viewDidLoad like this:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Difficulty"
      style:UIBarButtonItemStylePlain
      target:nil
      action:nil];

当用户按下视图中的另一个按钮时, UIBarButtonItem 更改如下:

When the user presses another button in the view, the title/text of the UIBarButtonItem is changed like this:

self.navigationItem.rightBarButtonItem.title = @"Mellansvår";

它工作正常,但是当标题改变时,它看起来不太好。文字跳了一下。

It works fine, but when the title is changed, it doesn't look very good. The text jumps around a bit.

我之前在运行时更改了 UILabel 文本,当我更改文本时看起来不像这样,但我不知道如何将 UILabel 添加到 navigationItem 。我无法在Interface Builder中执行此操作,因为导航栏来自 UINavigationController

I have changed UILabel text at runtime before, and when I change their text is doesn't look like this, but I don't know how to add a UILabel to the navigationItem. I can't do it in Interface Builder because the navigation bar comes from a UINavigationController.

是有没有办法更顺利地更改标题?

推荐答案

您可以设置再次使用标题按钮,然后为其设置动画:

Instead of setting the title again, you could set the button again with the title and then animate it:

(void)setRightBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated

这篇关于更改UIBarButtonItem标题时,转换是生涩/闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆