【问题标题】:How to show titles for UIToolBar items [duplicate]如何显示 UIToolBar 项目的标题 [重复]
【发布时间】:2017-08-21 19:11:17
【问题描述】:

是否有一种标准方法可以在UIToolBar 中显示工具栏项目的标题? UIBarButtonItem 具有图像和标题的属性,但是当我设置它们时,只出现图像。有没有办法同时显示标题(类似于 iOS 中的标准电话应用程序)?

我的代码:

let settings = UIBarButtonItem(image: #imageLiteral(resourceName: "settingsEmpty").withRenderingMode(.alwaysTemplate), style: .plain, target: self, action: nil)
settings.title = "Settings"
toolbarItems = [settings]

【问题讨论】:

  • 您在哪个标准 iOS 应用程序中看到工具栏上的标题和图像?您确定没有将工具栏与标签栏混淆吗?
  • 嗯..是的..你说得对,我想要一个看起来像工具栏的工具栏
  • 嗯?您想要一个看起来像工具栏的工具栏吗?你的意思是你想要一个看起来像标签栏的工具栏?
  • 工具栏看起来像一个标签栏

标签: ios swift uitoolbar


【解决方案1】:

不,标准控件中没有,您只能显示图像或标题。您必须创建一个自定义控件来执行此操作 - 对于UIBarButtonItem,您可以设置customView(并且由于工具栏可能太小,您可能还需要自定义其高度)。标题的目的是在没有图像时显示,或者为使用 VoiceOver 导航应用程序的用户朗读。

【讨论】:

    猜你喜欢
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多