How to reuse header section all scene?

后端 未结 3 862
天涯浪人
天涯浪人 2021-01-29 08:42

I want to reuse header section all view controller scene .header section mean green view and label (\"AMAR LIFE\")

Here is my may 1st

3条回答
  •  我在风中等你
    2021-01-29 09:38

    you need to add the following method in every view controller

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
        self.navigationController?.isNavigationBarHidden = false
        self.navigationController?.navigationBar.setBackgroundImage(#imageLiteral(resourceName: "123"), for: .default)
        self.title = "Hi I am tittle"
    }
    

    Also if you want to avoid code duplication and do more good just create one parent UIview and write this method in it and then inherit it in all the other views. However both solutions work fine. you can change the title and image according to your needs. Thanks

提交回复
热议问题