Based on the answers here I made this code:
extension NSMutableAttributedString {
func bold(text:String, size:CGFloat) -> NSMutableAttributedString {
let attrs:[String:AnyObject] = [NSFontAttributeName : UIFont.boldSystemFontOfSize(size)]
let boldString = NSMutableAttributedString(string:"\(text)", attributes:attrs)
self.appendAttributedString(boldString)
return self
}
func normal(text:String)->NSMutableAttributedString {
let normal = NSAttributedString(string: text)
self.appendAttributedString(normal)
return self
}
}
and I use it like this:
@IBOutlet weak var m_field: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
let string = NSMutableAttributedString()
string.bold("Bold_text: ",size: 12).normal("normal text")
m_field.attributedText = string
}
but it doesn't work, all my text is the same (bold I think) what am I doing wrong?