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.

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:


UILabel:
* Set Font

Table Of Contents
1 UILabel
12 UIView
15 UIColor
26 UIImage
28 CALayer
30 NSDate
40 iBeacon
49 NSTimer
79 NSURL
87 AWS SDK
96 NSData
101 Segues
104 EventKit
105 NSBundle
106 SiriKit
111 StoreKit
117 3D Touch
119 Keychain
122 Block
141 AirDrop
144 UISlider
145 Carthage
146 HealthKit
151 plist
157 MVVM
164 UIPhoenix
166 Simulator
168 NSArray
169 OpenGL
175 Core Data
179 MyLayout
180 UIFont
189 Security
200 Codable