简体   繁体   中英

how to make the label proportional to the screen size?

在此处输入图片说明

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

在此处输入图片说明

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) ?

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.

在此处输入图片说明

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

在此处输入图片说明

Set different font size using variations...

在此处输入图片说明

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 :

约束

结果

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM