How do I programmatically add a view right under the navigation bar?

前端 未结 6 956
轻奢々
轻奢々 2021-02-04 11:25

I\'m trying to add a view to a UINavigationController with its top aligned with the navigation bar\'s bottom.

I tried using constraints by adding the follo

6条回答
  •  自闭症患者
    2021-02-04 11:41

    override func viewDidAppear(_ animated: Bool) {
    let label = UILabel(frame: CGRect(x: 0, y: (navigationController?.navigationBar.frame.height)! + 20, width: UIScreen.main.bounds.width, height: 40))
    label.translatesAutoresizingMaskIntoConstraints = true
    label.text = "Hello"
    label.backgroundColor = UIColor.red
    self.view.addSubview(label)
    
    }
    

提交回复
热议问题