Underlining text in UIButton

后端 未结 18 1842
终归单人心
终归单人心 2020-11-29 15:56

Can anyone suggest how to underline the title of a UIButton ? I have a UIButton of Custom type, and I want the Title to be underlined, but the Interface Builder does not pr

18条回答
  •  抹茶落季
    2020-11-29 16:35

    In swift

    func underlineButton(button : UIButton) {
    
    var titleString : NSMutableAttributedString = NSMutableAttributedString(string: button.titleLabel!.text!)
    titleString.addAttribute(NSUnderlineStyleAttributeName, value: NSUnderlineStyle.StyleSingle.rawValue, range: NSMakeRange(0, button.titleLabel!.text!.utf16Count))
    button.setAttributedTitle(titleString, forState: .Normal)}
    

提交回复
热议问题