向NavigationBar中的preferredLargeTitles添加自定义视图

时间:2019-04-25 13:44:44

标签: swift uikit uinavigationbar

我有一个blueView,我想覆盖导航栏中的大标题区域(Fav10)。但是我无法访问它。将navBar的topItem.titleView设置为blueView只会给我2个标题。我该如何自定义该区域?

enter image description here

 override func viewDidLoad() {
    super.viewDidLoad()
    setupNavBar()
}

private func setupNavBar() {
    navigationItem.title = "Fav 10"
    let blueView = UIView()
    blueView.backgroundColor = .blue
    blueView.frame.size = CGSize(width: 40, height: 40)

    navigationController?.navigationBar.isTranslucent = false
    navigationController?.navigationBar.topItem!.titleView = blueView
    navigationController?.navigationBar.prefersLargeTitles = true
}

0 个答案:

没有答案