Add the following constraint For label
UILabel not adjusting when changing orientation
-
16-07-2023 - |
Domanda
I'm using auto layout, I have a label which is not adjusting its width when the device orientation is changing.
Label in the Landscape mode:
Label in the Portrait mode:
Label in design mode with constraints:
On the label, the following constraints exists:
- Width: greater or equal 220
- leading space of 20 the venue label which is static
- trailing space with the superview trailing
As you can see, the Portrait mode is ok, the problem is that when the orientation changes to landscape mode, the label remains how it is and does not adjust, why is that so? Am I missing any constraint?
Soluzione
Altri suggerimenti
You need to add height constraint along with constant great than equal to label. As in image below.=">
I tried this with a demo and worked as shown.
Also I applid following constraints to UILabel.So no need to applied width constraint. Just height constraint did it !
Here check below up down left and right constraint I applied and also height I ticked then I clicked width in IB where I changed the constant to >= and also I didn't ticked width. remove all constraint apply only below.