Last active
December 23, 2016 23:09
-
-
Save pangers/6a7afc0c28f70cbc1aee598d08265e71 to your computer and use it in GitHub Desktop.
This file contains 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 NSAttributedString { | |
func medium(sized size: CGFloat) -> NSAttributedString { | |
//1 | |
guard !string.isEmpty else { return } | |
//2 | |
let mutable = mutableCopy() as! NSMutableAttributedString | |
//3 | |
let attribute = [ | |
NSFontAttributeName : UIFont(name: "AvenirNext-Medium", size: size) | |
] | |
//4 | |
mutable.addAttributes(attribute, range: NSRange(location: 0, length: string.characters.count)) | |
return mutable | |
} | |
func colored(_ color: UIColor) -> NSAttributedString { | |
//1 | |
guard !string.isEmpty else { return } | |
//2 | |
let mutable = mutableCopy() as! NSMutableAttributedString | |
//3 | |
let attribute = [ | |
NSForegroundColorAttributeName : color | |
] | |
//4 | |
mutable.addAttributes(attribute, range: NSRange(location: 0, length: string.characters.count)) | |
return mutable | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment