How to display Underlined Text in a Button on iOS?

后端 未结 10 1648
日久生厌
日久生厌 2020-12-16 15:20

I want to display the mail ID in my view such that clicking the mail ID should open the mail composer view.

I want to display the button text as underlined to show i

10条回答
  •  长情又很酷
    2020-12-16 15:22

    Adding a screenshot for @Haider's answer.

    Note: Only the text you highlight gets underlined, so you can underline just a specific range if you want.

    I ended up underlining it in code anyway, just because I couldn't get Bold to work in conjunction with Underline for some reason. Could have been because of the font I was using, who knows.

    @IBOutlet weak var underlineButton: UIButton! {
        didSet {
            let attrs = [
                NSFontAttributeName : UIFont(name: "MyCustomFont-Bold", size: 19.0)!,
                NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue,
                NSForegroundColorAttributeName : UIColor.orangeColor()
            ]
            let attrString = NSMutableAttributedString(string: "Button text", attributes:attrs)
            underlineButton.setAttributedTitle(attrString, forState: .Normal)
        }
    }
    

提交回复
热议问题