Skip to content

Instantly share code, notes, and snippets.

@codetalks-new
Created January 10, 2015 07:43
Show Gist options
  • Save codetalks-new/457436724a294903fd21 to your computer and use it in GitHub Desktop.
Save codetalks-new/457436724a294903fd21 to your computer and use it in GitHub Desktop.
a Simple AttributedString Demo
class TextCommentView:UILabel{
var name :String = ""{
didSet{
updateText()
}
}
var comment:String = ""{
didSet{
updateText()
}
}
func updateText(){
numberOfLines = 2
let nameAttr:NSDictionary = [
NSFontAttributeName:UIFont.systemFontOfSize(13),
NSForegroundColorAttributeName:blueColor
]
let nameAttrString = NSAttributedString(string: name, attributes: nameAttr)
let commentAttr:NSDictionary = [
NSFontAttributeName:UIFont.systemFontOfSize(12),
NSForegroundColorAttributeName:UIColor.darkGrayColor()
]
let commentAttrString = NSAttributedString(string: " :"+comment, attributes: commentAttr)
let attrString = NSMutableAttributedString(attributedString: nameAttrString)
attrString.appendAttributedString(commentAttrString)
self.attributedText = attrString
layoutIfNeeded()
}
}
let textCommentView = TextCommentView(frame: CGRect(x: 0, y: 0, width: 240, height: 60))
textCommentView.backgroundColor = UIColor.whiteColor()
textCommentView.comment = demoSummary()
textCommentView.name = demoName()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment