在导航栏左侧添加标题 [英] Adding a title to the left side of the navigation bar

查看:23
本文介绍了在导航栏左侧添加标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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