Skip to content

Instantly share code, notes, and snippets.

@bagpack
Created October 11, 2017 05:40
Show Gist options
  • Save bagpack/d9a944b4ba2e74862629b5b8501f4e07 to your computer and use it in GitHub Desktop.
Save bagpack/d9a944b4ba2e74862629b5b8501f4e07 to your computer and use it in GitHub Desktop.
Colorized
extension String {
func colorized(rangeOf: String, color: UIColor, font: UIFont) -> NSAttributedString {
let string = self as NSString
let range = string.range(of: rangeOf)
let attributedText = NSMutableAttributedString(string: self)
attributedText.addAttributes([NSForegroundColorAttributeName: color], range: range)
attributedText.addAttributes([NSFontAttributeName: font], range: range)
return attributedText
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment