Search code examples
swiftuilabelbold

Swift: Programmatically make UILabel bold without changing its size?


I have a UILabel created programmatically. I would like to make the text of the label bold without specifying font size. So far I have only found:

UIFont.boldSystemFont(ofSize: CGFloat) 

This is what I have exactly:

let titleLabel = UILabel()
let fontSize: CGFloat = 26
titleLabel.font = UIFont.boldSystemFont(ofSize: titleLabelFontSize)

But this way I am also setting the size. I would like to avoid that. Is there a way?

If there is no way, what would be a good workaround in Swift?

Thank you!


Solution

  • Why not just:

    titleLabel.font = UIFont.boldSystemFont(ofSize: titleLabel.font.pointSize)