Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: Programmatically make UILabel bold without changing its size?

Tags:

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!

like image 268
user1269290 Avatar asked Oct 12 '16 12:10

user1269290


People also ask

How do I make my text bold on UILabel?

Write the following text in the label “Bold Regular”Double Click on Bold to select it, and then right click on it to see more options. Select font > Bold from that option. It should do the task.

How do you change the font size on UILabel?

Change Font And Size Of UILabel In StoryboardSelect the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.


1 Answers

Why not just:

titleLabel.font = UIFont.boldSystemFont(ofSize: titleLabel.font.pointSize) 
like image 89
Chris Vig Avatar answered Oct 21 '22 05:10

Chris Vig