Swift add constraint programmatically

后端 未结 5 1765
盖世英雄少女心
盖世英雄少女心 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:44

    The error states that "because they have no common ancestor", which means that they don't share the same parent. In order to relate constraint between two items, they have to have a child-parent relationship or a sibling one.

    In your case just make sure they have the same parent view before adding the constraint programmatically.

提交回复
热议问题