我在设置 self.navigationItem.titleView
时遇到问题,有人可以帮我找出错误吗。
import Foundation
class CustomNavigationController: UINavigationController
{
override func viewDidLoad() {
let logo = UIImage(named: "browse_back")
var hexColor = 0x21BBD4 as UInt
self.navigationBar.barTintColor = GeneralHelper.UIColorFromRGB(hexColor)
self.navigationItem.titleView = UIImageView(image: logo)
}
}
这是我将 titleView 设置为图像的代码。
当我运行应用程序时,导航栏的颜色正在更改为正确的颜色,但 titleView 图像未显示。
- 我已进行测试以确保图像确实存在。
谢谢。
最佳答案
The managing
UINavigationController
object uses the navigation items of the topmost two view controllers to populate the navigation bar with content.
来源:UINavigationItem Class Reference
您必须设置 Controller 的 navigationItem
的 titleView
,该 Controller 是您的自定义导航 Controller 管理的导航堆栈中最顶层的 Controller 。
关于ios - 自定义 navigationItem.titleView 未设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28085685/