Lücks
Lücks

Reputation: 3984

Changing UILabel font size with AutoLayout

I'm working with Swift, IOS 8 and AutoLayout. I have a big label, size 40 on center of the screen.

I want that on iPhone 5s- the size of label becomes like 34, and on iPad a bigger font size, like 50.

How can I do this with AutoLayout?

Upvotes: 4

Views: 9310

Answers (3)

person
person

Reputation: 123

Step 1 : Select UILabel and Click on plus icon in Attribute Inspector

enter image description here

Step 2 : To add font size for new device let suppose Iphone Portrait, hover on Compact Width -> Any Height.

enter image description here

Step 3 : Now change this new font to 25 i.e for iphone. And on the Font above it to be 70 which is now for devices other than iphone portrait.

enter image description here

Step 4 : Output on iphone6 vs Ipad Retina

enter image description here

enter image description here

Upvotes: 1

Tim
Tim

Reputation: 9042

You can set a minimum font size as well as the maximum font size you want on the label, then apply constraints on the edges and let the intrinsic content size of text determine the size of the label.

Upvotes: 0

Lücks
Lücks

Reputation: 3984

I found a solution: Just go to your storyboard, click on your label and then click on "+" on the left of "Font" (Attributes Inspector) and add another font with a different size:

Adding multiple font's size

On my case, I added for iPad a size of 50. Worked perfectly!

Upvotes: 16

Related Questions