1

I want half of my UILabel's text to be bold and half to not be bold. How can I do this?

jscs
  • 63,694
  • 13
  • 151
  • 195
max_
  • 24,076
  • 39
  • 122
  • 211

3 Answers3

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
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.

Community
  • 1
  • 1
Simon
  • 8,981
  • 2
  • 26
  • 32
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