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.
这篇关于在导航栏左侧添加标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:在导航栏左侧添加标题
基础教程推荐
猜你喜欢
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
