Created
October 11, 2017 05:40
-
-
Save bagpack/d9a944b4ba2e74862629b5b8501f4e07 to your computer and use it in GitHub Desktop.
Colorized
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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