Posts

Showing posts from October, 2021

Swift: Make part of text bold

Image
 Hello everyone, You may have encountered situations where you want to display part of your label's string as bold, while keeping the other part as normal. It's very easy using an attributed string. Below is the code that you need to accomplish this. let attrs = [ NSAttributedString . Key . font : UIFont (name: <your custom font name> , size: <your font size> )] let attributedString = NSMutableAttributedString (string:boldText, attributes:attrs as [ NSAttributedString . Key : Any ]) let normalText = normalText let normalString = NSMutableAttributedString (string:normalText) attributedString. append (normalString)          Now, set the attributed string to your UILabel instance. E.g someLabel . attributedText = attributedString That's it. You can play around with this and see how you can achieve other results with the attributed Strings!