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:

enter image description here

Label in the Portrait mode:

enter image description here

Label in design mode with constraints:

enter image description here On the label, the following constraints exists:

  1. Width: greater or equal 220
  2. leading space of 20 the venue label which is static
  3. 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?

È stato utile?

Soluzione

Add the following constraint For label

constraint

Altri suggerimenti

You need to add height constraint along with constant great than equal to label. As in image below.Height constraint with constant  loading==">

I tried this with a demo and worked as shown.

Portrait Mode

Landscape Mode

Also I applid following constraints to UILabel.So no need to applied width constraint. Just height constraint did it ! enter image description here

enter image description here 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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top