Swift add constraint programmatically

后端 未结 5 1764
盖世英雄少女心
盖世英雄少女心 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条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 08:41

    Checklist for this ISSUE:

    • Check whether you added the programmatically created view to its parent before activating constraints
    • Check whether you write constraints activation code inside viewDidLoad() / viewWillAppear(). You should write constraints activation code in updateViewConstraints or viewWillLayoutSubviews. ( suggested by vmeyer )
    • Check whether you turn off translatesAutoresizingMaskIntoConstraints.

提交回复
热议问题