ios - iOS 栏按钮项目中的动态文本

标签 ios uibarbuttonitem

我想将动态文本放入栏按钮项目中,类似于《纽约时报》对其评论数量的处理方式,如下图所示。

关于如何实现此功能有什么想法吗?

enter image description here

最佳答案

我认为关键是 - initWithCustomView: UIBarButtonItem 的方法。 下面是伪代码,根据需要修改:

UICustomViewController *customVC = [[UICustomViewController alloc] initWithNibName:@"UICustomViewController" bundle:nil];
[customVC loadView];  //load the views, so your views won't be nil
[customVC updateText];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:customVC.view];
[[self navigationItem] setRightBarButtonItem:barButtonItem];

关于ios - iOS 栏按钮项目中的动态文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29641104/

相关文章:

ios - 如何在 2019 年使用正确的配置文件通过命令行构建 Xcode 项目?

ios - FaceBook IOS SDK - GitHub

ios - 是否可以在 UISegmentedControl 之外添加 UIBarButtonItem?

ios - 如何以编程方式获取 UIBarButtonItem 的状态?

ios - 导航 Controller 中的静态 barButtonItems?

ios - UIBarButtonItem 的背景阴影

ios - 使用密码保存 PDF iOS

ios - 滑动手势即可将键盘隐藏在UITextView中

ios - 在iOs中,是否可以通过编程方式停止从AppStore自动更新我的应用程序?

ios - 在其图像上显示 UIBarButton 标题