JimmyLee
JimmyLee

Reputation: 569

How to change label size according to device Text Size - Swift 3?

I change my text size like following image.

But my app doesn't change the the font size.

Have any idea to me?

label.font = UIFont.systemFont(ofSize: 16.0)
label.adjustsFontForContentSizeCategory = YES
label.text = string

enter image description here

Upvotes: 0

Views: 855

Answers (2)

Sandeep Bhandari
Sandeep Bhandari

Reputation: 20379

From iOS 10 onwards you can support dynamic font sizes using one line :)

Change your

label.font = UIFont.systemFont(ofSize: 16.0)

to use,

label.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.headline)

You can specify the font style you need for your label :)

Refer : https://developer.apple.com/documentation/uikit/uifont/1619030-preferredfont

Upvotes: 3

Rashed
Rashed

Reputation: 2425

There is a simpler solution. Just add below lines-

SWIFT 3:

label.minimumScaleFactor = 0.1    //or whatever suits your need
label.adjustsFontSizeToFitWidth = true    
label.lineBreakMode = .byClipping
label.numberOfLines = 0

Upvotes: 0

Related Questions