iOS Set Font


Example

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

iOS 8.2

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];
iOS 8.2

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.

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