I have a UIComponent which is a simple view (I narrowed the problem). Here is the xib and class :
Then I put this component in a view in the storyboard, sets its constraints:
So normally the red rectangle has different width value depending on the device width.
This is the case graphically, the component resizes itself correctly, but when I call the function to print its width, the result is always the same, whatever the device that launch the app.
In fact, the value is always the actual width of the component in the storyboard.
This is so weird. Is there a way to know the actual width of the UIComponent ?
Help would be greatly appreciated :)
You should use layoutIfNeeded() on your view after setting up the constraints but before trying to get its width. Constraints are not applied right at the moment of activation
(sorry for 2 answers ^^ they're just too different)