I have UIButton. In interface builder I set its title to be \'Attributed\'. How can I make its title to be underlined from code in Swift?
@IBOutlet weak var myBt
Thanks for posting your code, it wasn't clear that you knew how to create an attributed string at all.
This should work:
var attrs = [
NSFontAttributeName : UIFont.systemFontOfSize(19.0),
NSForegroundColorAttributeName : UIColor.redColor(),
NSUnderlineStyleAttributeName : NSUnderlineStyle.StyleSingle.rawValue
]
Swift 4 version:
var attrs : [NSAttributedStringKey : Any] = [
NSAttributedStringKey.font : UIFont.systemFont(ofSize: 19.0),
NSAttributedStringKey.foregroundColor : UIColor.red,
NSAttributedStringKey.underlineStyle : NSUnderlineStyle.styleSingle.rawValue
]