Swift add constraint programmatically

后端 未结 5 1777
盖世英雄少女心
盖世英雄少女心 2021-01-31 08:23

I add a UILabel (amountLabel) in UIViewController in storyboard editor. And then in swift file, viewDidLoad, I programatically create a

5条回答
  •  长发绾君心
    2021-01-31 08:31

    let nameLabel: UILabel = {
    
       let label = UILabel()
        label.translatesAutoresizingMaskIntoConstraints = false
        return label
    }()
    

    if you forgot setting this label.translatesAutoresizingMaskIntoConstraints = false or if you add subview after constraints this problem arises

提交回复
热议问题