Skip to content

Instantly share code, notes, and snippets.

@TramPamPam
Created April 2, 2019 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TramPamPam/33db00475282894f6e72a96e1f6623c1 to your computer and use it in GitHub Desktop.
Save TramPamPam/33db00475282894f6e72a96e1f6623c1 to your computer and use it in GitHub Desktop.
private func highlight(_ substring: String, in string: String, color: UIColor = UIColor(named: "Blue")!) -> NSAttributedString {
let defaultAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14.0),
NSAttributedString.Key.foregroundColor: UIColor.white]
let text = NSMutableAttributedString(string: string, attributes: defaultAttributes)
if let fillableRange = string.nsRange(of: substring) {
text.addAttribute(NSAttributedString.Key.font, value: UIFont.boldSystemFont(ofSize: 14.0), range: fillableRange)
text.addAttribute(NSAttributedString.Key.underlineColor, value: color, range: fillableRange)
text.addAttribute(NSAttributedString.Key.underlineStyle, value: 1, range: fillableRange)
}
return text
// fillableLabel.attributedText = text
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment