Customize navigation bar with title view

前端 未结 8 2296
一生所求
一生所求 2020-12-08 13:41

I am trying to add a custom view in the center of a navigation bar and I am using the following code to test it:

UIView * testView = [[UIView alloc] init];
[         


        
8条回答
  •  暖寄归人
    2020-12-08 14:15

    Swift 3

    let myImageView = UIImageView(image: <...set your image...>)
    
    override fun viewDidLoad(){
       super.viewDidLoad()
       self.navigationItem.titleView = myImageView  //
    }
    

    One more alternate solution is

    override fun viewWillAppear(_ animated: Bool) {
       super. viewWillAppear(animated)
       self.navigationItem.titleView = myImageView
    }
    

    I recommend to use, viewDidLoad to setup your titleView

提交回复
热议问题