How to add Attributed String in label.
let attributedStr = NSMutableAttributedString(string: "Hi " , attributes:[NSAttributedStringKey.font : UIFont(name: FontName.OpenSans_Regular , size: FontSize.SIXTEEN)!, NSAttributedStringKey.foregroundColor : COLOR.Black])
let attributedStr1 = NSMutableAttributedString(string: " My Name is" , attributes:[NSAttributedStringKey.font : UIFont(name: FontName.OpenSans_Bold , size: FontSize.SIXTEEN)!, NSAttributedStringKey.foregroundColor : COLOR.Blue])
let attributedStr2 = NSMutableAttributedString(string: "Harsh" , attributes:[NSAttributedStringKey.font : UIFont(name: FontName.OpenSans_Regular , size: FontSize.SIXTEEN)!, NSAttributedStringKey.foregroundColor : COLOR.Green])
let attributedStr3 = NSMutableAttributedString(string: "How are you", attributes:[NSAttributedStringKey.font : UIFont(name: FontName.OpenSans_Bold, size: FontSize.SIXTEEN)!, NSAttributedStringKey.foregroundColor : COLOR.Grey])
attributedStr.append(attributedStr1)
attributedStr.append(attributedStr2)
attributedStr.append(attributedStr3)
lblMessage.attributedText = attributedStr
Comments
Post a Comment