I want half of my UILabel
's text
to be bold and half to not be bold. How can I do this?
Asked
Active
Viewed 1,654 times
1
3 Answers
8
NSAttributedString allows for specification of formatting within a string, but sadly, UIKit does not yet do anything with this. However, there are a few open-source implementations that do. Check out OHAttributedLabel.

Christopher A
- 2,961
- 1
- 22
- 23
-
Thanks for mentionning my class Christopher :) – AliSoftware Oct 03 '11 at 10:47
-
OHAttributedLabel has not maintaining anymore by the creator. – ersentekin May 07 '15 at 10:24
1
You can't do this easily unless you subclass UILabel and mess with the subviews. Better to use two UILabels instead. Found another thread about it here.
0
UILabel has attributedText
which takes a NSAttributedString
which allows you to customize multiple aspects of a string including changing the font type and other attributes
var attributedString = NSMutableAttributedString(attributedString: NSAttributedString(string: "Not Bold"))
let boldAttrString = NSAttributedString(string: "BOLD", attributes: [NSFontAttributeName: UIFont(name: "Avenir-Medium", size: 15)!])
attributedString.appendAttributedString(boldAttrString)
myLabel.attributesText = attributedString

Nick Wargnier
- 1,461
- 14
- 8