在导航栏左侧添加标题

Adding a title to the left side of the navigation bar(在导航栏左侧添加标题)
本文介绍了在导航栏左侧添加标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在导航栏的左侧添加标题?我知道如何在中心添加标题,但是当我尝试在左侧添加标题时,我什么也看不到.这是我的代码:

Is it possible to add a title to the left side of the navigation bar? I know how I can add a title in the center but when I try to add one to the left side I see nothing. This is the code I have:

self.navigationItem.leftBarButtonItem?.title = "Elapsed Time: 0:00"

感谢您的帮助.

推荐答案

试试这个代码:

let leftItem = UIBarButtonItem(title: "Title",
                                   style: UIBarButtonItemStyle.plain,
                                   target: nil,
                                   action: nil)
    leftItem.isEnabled = false
    self.navigationItem.leftBarButtonItem = leftItem

这个问题更强大的解决方案:

More powerful solution of this problem:

let longTitleLabel = UILabel()
    longTitleLabel.text = "Long long long long long long title"
    longTitleLabel.font = ................
    longTitleLabel.sizeToFit()

    let leftItem = UIBarButtonItem(customView: longTitleLabel)
    self.navigationItem.leftBarButtonItem = leftItem

现在您可以根据需要编辑标签.您可以使用其他字体或文本颜色.

Now you just can edit label as you want. You can use another font or text color.

这篇关于在导航栏左侧添加标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)