Inside storyboard files, setting constraints and some variation for different device variation, that is with either compact or regular width and height is quite easy.
Now in the code part, setting constraints is also simple but is it possible to set a constraint value for a certain device variation?
For the iPad it would be wR hR and for the iPhone 8 Plus wC hR, so I would like to know whether it is posiible to set a variation in the constraint programmatically, or atleast change the constraint variation value for a certain device programmatically through a constraint outlet.
Thank You and have a good day.
Sincerely yours, SamS19
It appears there is no way to access specific variation constant values currently. In code it looks like you only see the "current" value of the constraint constant. And if you modify that constraint constant, UIKit will overwrite it with whatever you specified on the storyboard the next time it does a layout pass anyway. So you would have to adjust the constant *after* UIKit has done its thing (in viewDidLayoutSubviews for example).
It might be easier to not fight the system and either go with all IB or all code (create different sets of constraints and install/uninstall them in viewWillTransitionToSize when the trait collection changes) solutions for now. It would certainly be nice to be able to access the constant values for different trait collections in code... feel free to file an enhancement request 🙂