0

Just simple question. How to make the size of the UILabel following device size?

for example, I have 1 label that have size 20 running on iPhone 5. Then if running on iPhone 6 the label size changed to 40. What should I do?

Bhavin Ramani
  • 3,133
  • 5
  • 29
  • 41
Ariel Gemilang
  • 722
  • 1
  • 14
  • 38

2 Answers2

2

If you are using autolayout and you want to increase height and width of label with respect to screen size then you should simply give four constraint to label like : top,bottom,leading and trailing

If you want to increase height and with with in specific desired value, for example if you want label width exact half of screen width, In this type of case you should give constraints like : leading,top,fix height, fix width. Then, select fixed width constraint and from size inspector change it's multiplier to 0.5. so your label width always remains half of screen width. you can do same for height. and you can set different multiplier value to get desired output.

Hope this will help :)

Ketan Parmar
  • 25,426
  • 9
  • 43
  • 67
0

Normally I will use ratio to define the constraint. For example, if your label height design is 40 px for iPhone 6, I will define the label constraint by setting equal height of the label and the main view. After that change the multipler of the constraint to 40:1334. The label will have exact same ratio of the screen.

Jason Chan
  • 25
  • 4