Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attributed String only to change Font Size, not the font name

I am trying to set attributed text to a label. However, I want to change the size but not want to set the font name, how do I do that?

let myAttributedString = NSMutableAttributedString(string: "Some Text",
 attributes: [NSFontAttributeName:UIFont(name: "Georgia",size: 18.0)!])

2 Answers

You can use this,

Your_Label.font.withSize(20)

Your end string will be,

let myAttributedString = NSMutableAttributedString(string: "Some Text", attributes: [NSFontAttributeName:Your_Label.font.withSize(15)])
like image 64
PPL Avatar answered Oct 20 '25 08:10

PPL


Get the font name from label.

let myAttributedString = NSMutableAttributedString(string: "Some Text", attributes: [NSFontAttributeName:UIFont(name: label.fontName, size: 18.0)!]) 
like image 43
Puneet Sharma Avatar answered Oct 20 '25 08:10

Puneet Sharma