0

I need to put HTML text with bold,italic and links in a UILabel. If I use NSAttributedString the links aren't clickable. If I use TTTAttributedLabel links are clickable but the formatting (bold and italic) is not visibile.

This problem drive me crazy! Ideas?

Fry
  • 6,235
  • 8
  • 54
  • 93

1 Answers1

0

You can make the link formatting work using TTTAttributedLabel. For example, this will color links blue and underline them (in Swift):

let bodyLabel: TTTAttributedLabel

let content = "TTTAttributedLabel will detect http://example.com"
let attributedContent = NSMutableAttributedString(string: content)

// add some attributes as you need to the attributed string, then...

let blueLinks = [NSForegroundColorAttributeName: UIColor.blueColor()]

bodyLabel.enabledTextCheckingTypes = NSTextCheckingType.Link.rawValue
bodyLabel.linkAttributes = blueLinks

bodyLabel.setText(attributedContent)
Mathew Spolin
  • 371
  • 1
  • 11