0

If I create a label like this:

var label = UILabel(...)
label.text = first_name + ", " + age
self.view.addSubview(label)

How can I change the age of the label to bold, but keep the first_name normal weight?

TIMEX
  • 238,746
  • 336
  • 750
  • 1,061
  • You need to use NSAttributedString which is a special string that lets you makes pieces of it look different (i.e. bolding)...then set the label.attributedText instead – DBoyer Aug 01 '15 at 22:30

1 Answers1

7

You can use an attributed string. Here, the bold size is 15, but you can also change that point size if you want.

var age = "13"

var att = [NSFontAttributeName : UIFont.boldSystemFontOfSize(15)]

var boldAge = NSMutableAttributedString(string:age, attributes:att)

// Assigning to a UILabel
yourLabel.attributedText = boldAge

so now you would want to assign your text like this:

label.attributedText = first_name + ", " + boldAge
Cole
  • 2,601
  • 1
  • 15
  • 32