Set Font

suggest change

Swift

let label = UILabel()

Objective-C

UILabel *label = [[UILabel alloc] init];
// or
UILabel *label = [UILabel new]; // convenience method for calling alloc-init

Change the default font’s size

Swift

label.font = UIFont.systemFontOfSize(17)

Swift 3

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

Objective-C

label.font = [UIFont systemFontOfSize:17];

Use a specific font weight

Swift

label.font = UIFont.systemFontOfSize(17, weight: UIFontWeightBold)

Swift3

label.font = UIFont.systemFont(ofSize: 17, weight: UIFontWeightBold)

Objective-C

label.font = [UIFont systemFontOfSize:17 weight:UIFontWeightBold];

Swift

label.font = UIFont.boldSystemFontOfSize(17)

Swift3

label.font = UIFont.boldSystemFont(ofSize: 17)

Objective-C

label.font = [UIFont boldSystemFontOfSize:17];

Use a Dynamic Type text style.

The font and point size will be based on the user’s preferred reading size. This does not track later Dynamic Type changes unless adjustsFontForContentSizeCategory is set (iOS 10) or the label is updated when the category changes. UIFont(name:size:) later on this page is nil when the name is not installed. The weight: initializer is iOS 8.2 and later.

Swift

label.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)

Swift 3

label.font = UIFont.preferredFont(forTextStyle: .body)

Objective-C

label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];

Use a different font altogether

Swift

label.font = UIFont(name: "Avenir", size: 15)

Objective-C

label.font = [UIFont fontWithName:@"Avenir" size:15];

Override font size

A way to set the font size without knowing the font family is to use the font property of the UILabel.

Swift

label.font = label.font.fontWithSize(15)

Swift 3

label.font = label.font.withSize(15)

Objective-C

label.font = [label.font fontWithSize:15];

Use Custom Font Swift

Refer to this link

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents