2

enter image description here

I am a beginner, I am trying to do an autolayout. I am trying to make the label 'HRIS' and 'Please login to continue' to be proportional to the screensize (its superview), I can do it for the login button and the image leaf as the picture above, we can see that the login button and leaf image are proportional.

for the image leaf, I do equal width with 0,1 multiplier to the superview, and then I also add 'aspect ratio' to make it proportional.

but when I apply the same way to the label, it doesn't work, as we can see the label size still the same for iphone 4s and iphone 8, maybe it is because the instrinsict content size (the font size itself) that makes it like that. I tried to apply this way, but it seems the size is still the same

enter image description here

I want to make it little bit smaller for iphone 4s, I also can't modify using size classes since it is in the same class

so what I have to do to make label proportional to the superview (screen size / background) ?

Alexa289
  • 8,089
  • 10
  • 74
  • 178

3 Answers3

2

You can do it by setting both proportional width of the label and allow it to scale down the point size.

Set the label width to proportional width like this. It is just a regular same width constraint that you edit.

enter image description here

Then allow your label to scale down the point size like this. This is a property of your label.

enter image description here

LGP
  • 4,135
  • 1
  • 22
  • 34
0

Set different font size using variations...

enter image description here

Tomasz Czyżak
  • 1,118
  • 12
  • 13
  • Thank you very much Tomasz, but I little bit confused all those in my picture above are compact width and regular height, so how can I make variation for screens in the same class? – Alexa289 Feb 17 '18 at 10:29
  • All iPhones have the same [Size Class](https://developer.apple.com/ios/human-interface-guidelines/visual-design/adaptivity-and-layout/#device-size-classes). – clemens Feb 17 '18 at 10:30
  • so maybe programatically change font size depending on screen width? – Tomasz Czyżak Feb 17 '18 at 17:56
0

Simply set up a constraint for your label's width to be equal the view's width with your desired multiplier. In my example I used a multiplier of 0.5:

constraint

result

André Slotta
  • 13,774
  • 2
  • 22
  • 34
  • thank you very much Andre for your help, yes I use that way in my label as well, it seems the font size still the same, I just build a view controller that contains only one label that has font size 500 and has only one character to prove it, but I think the font size is still the same using this way, I add the image n my post – Alexa289 Feb 17 '18 at 10:42