Set bold and regular fonts to one label text iOS swift
Problem:
I want to set bold font with one text and normal font with another text to UILabel.By default we can set the font to label.But it's different.How to achieve that?
Solution:
It's easy because iOS had a concept of attributed text.So we can set the different attributes to one label.You can solve the above problem by the following methid.
let notesAttributes:[NSAttributedString.Key: Any] = [.font : UIFont(name: "Roboto-Bold", size: 14)!]
let otherAttributes:[NSAttributedString.Key: Any] = [.font : UIFont(name: "Roboto-Regular", size: 14)!]
let note = NSAttributedString(string: "Note: ", attributes:notesAttributes)
let other = NSAttributedString(string: "Your profile cannot be recovered", attributes:otherAttributes)
let text = NSMutableAttributedString()
text.append(note)
text.append(other)
lbl.attributedText = text
Comments
Post a Comment