label.font.pointSize is read-only, so I'm not sure how to change it.
-
extension UILabel{ func font(size: CGFloat){ self.font = UIFont(descriptor: self.font.fontDescriptor, size: size) } }Mohammad Razipour– Mohammad Razipour2018-09-09 07:21:42 +00:00Commented Sep 9, 2018 at 7:21
21 Answers
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)
10 Comments
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.
Comments
label.font = UIFont.systemFontOfSize(20)
2 Comments
If you want just change size of your font i create this extension
// Add extension
extension UILabel {
func setSizeFont (sizeFont: Double) {
self.font = UIFont(name: self.font.fontName, size: sizeFont)!
self.sizeToFit()
}
}
// Use
myLabel.setSizeFont(60)
1 Comment
Programmatically
label.font = UIFont.systemFont(ofSize: 20.0)
label.font = UIFont.boldSystemFont(ofSize: 20.0)
label.font = UIFont.italicSystemFont(ofSize: 20.0)
label.font = UIFont(name:"Helvetica Neue", size: 20.0)//Set your font name here
Through Story board
To display multiple lines set 0(Zero), this will display more than one line in your label.
If you want to display only 2 lines set 2.
If you want to set minimum font size for label Click Autoshrink and Select Minimum Font Size option
See below screens
Here set minimum font size
EX: 9 (In this image)
If your label get more text at that time your label text will be shrink upto 9
Comments
In Swift 3:
label = UIFont.systemFont(ofSize: 20)
and to use system preset sizes, for example:
label = UIFont.systemFont(ofSize: UIFont.smallSystemFontSize)
1 Comment
SWIFT 3.1
Label.font = Label.font.withSize(NewValue)



