Created
January 6, 2015 10:01
-
-
Save cemolcay/e76ec9334574d2af595a 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 UILabel { | |
func addAttributedString (text: String, color: UIColor, font: UIFont) { | |
var string = self.text == nil ? "" : self.text! | |
let newString = string + text | |
let range = NSRange(location: countElements(string), length: countElements(text)) | |
var att: NSMutableAttributedString? | |
if let a = self.attributedText { | |
att = NSMutableAttributedString (attributedString: a) | |
att?.appendAttributedString(NSAttributedString (string: text)) | |
} else { | |
att = NSMutableAttributedString (string: newString) | |
} | |
att!.addAttribute(NSFontAttributeName, value: font, range: range) | |
att!.addAttribute(NSForegroundColorAttributeName, value: color, range: range) | |
self.attributedText = NSAttributedString (attributedString: att!) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment