Where should I be setting autolayout constraints when creating views programmatically

后端 未结 8 738
不思量自难忘°
不思量自难忘° 2020-12-07 07:52

I see different examples where constraints are set. Some set them in viewDidLoad / loadView (after the subview was added). Others set them in the m

8条回答
  •  一向
    一向 (楼主)
    2020-12-07 08:35

    You can set them in viewWillLayoutSubviews: too:

     override func viewWillLayoutSubviews() {
    
        if(!wasViewLoaded){
            wasViewLoaded = true
    
            //update constraint
    
            //also maybe add a subview            
        }
    }
    

提交回复
热议问题