是否可以在导航栏的左侧添加标题?我知道如何在中心添加标题,但是当我尝试在左侧添加标题时,我什么也看不到.这是我的代码:
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.
这篇关于在导航栏左侧添加标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!