1

I applied flexible height & width to my UILabel and now I want to use that type of functionality by using Auto Layout.

I am able to increase height and width of UILabel as Device width and height, but X and Y is not changed according to Device width and Height.

Ex:-

Device :- iPhone 7
UILabel :-
        X      : 20
        Y      : 120
        Width  : 300
        Height : 30


Device :- iPhone SE
UILabel :-
        X      : 20 
        Y      : 120
        Width  : 245
        Height : 25

Now problem is that Size of UILabel decrease with aspect ratio but X & Y coordinate was not changed. According to flexible height & width that will set like 17 & 102, but in auto layout it was not change.

Constraint :

Constraint Image

Dev Patel
  • 13
  • 5

2 Answers2

0

You have fixed X and Y Position for your label (Which is not device specific)

If you need to achieve this you need to set X and Y according to Centre of your view

I have create to set centre X (For Y Pos )

enter image description here

enter image description here

And How I have set centre of Y Pos

enter image description here

EXPLAINATION

The centre of UIView according to self.view is 318.5 and required space from top is 20 so final multiplier is 20:318.5

as every view has different centre For Iphone SE centre would be around 17

Don't Forgot to set First Item to Label.Top as we need 20 from TOP

OUTPUT:

enter image description here

Hope it is clear to you :)

Prashant Tukadiya
  • 13,804
  • 3
  • 55
  • 78
  • That's work :) Thanks a lot for a great example... Jon Snow – Dev Patel Sep 20 '17 at 04:48
  • @DevDev Glad the solution worked. Would you mind accepting this answer? It might help people experiencing a similar issue and will help getting your question noticed. For more information, take a look at our [FAQ](https://stackoverflow.com/help/accepted-answer). Thanks and welcome to SO! – Prashant Tukadiya Sep 20 '17 at 04:57
0

I have attach a image to make a label height dynamically. Select trailing constraint and change relation from "Equal" to "Greater Than Equal". Make sure number of line of label should should be "0".

enter image description here

Shiv Kumar
  • 832
  • 7
  • 11