Skip to content

Instantly share code, notes, and snippets.

@pangers
Last active December 23, 2016 23:09
Show Gist options
  • Save pangers/6a7afc0c28f70cbc1aee598d08265e71 to your computer and use it in GitHub Desktop.
Save pangers/6a7afc0c28f70cbc1aee598d08265e71 to your computer and use it in GitHub Desktop.
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