How do I change the font size of a UILabel in Swift? How do I change the font size of a UILabel in Swift? ios ios

How do I change the font size of a UILabel in Swift?


You can do it like this:

label.font = UIFont(name: label.font.fontName, size: 20)

Or like this:

label.font = label.font.withSize(20)

This will use the same font. 20 can be whatever size you want of course.

Note: The latter option will overwrite the current font weight to regular so if you want to preserve the font weight use the first option.

Swift 3 Update:

label.font = label.font.withSize(20)

Swift 4 Update:

label.font = label.font.withSize(20)

or

label.font = UIFont(name:"fontname", size: 20.0)

and if you use the system fonts

label.font = UIFont.systemFont(ofSize: 20.0)label.font = UIFont.boldSystemFont(ofSize: 20.0)label.font = UIFont.italicSystemFont(ofSize: 20.0)


I think the best way to do this - if keeping the same font that is already assigned to the UILabel would be:

(using Swift)

label.font = label.font.fontWithSize(20)

(using Swift 3)

label.font = label.font.withSize(20)

Ideally I would set this in the viewDidLayoutSubviews method, as it doesn't need to change every time the view appears.


label.font = UIFont.systemFontOfSize(20)