How to display Underlined Text in a Button on iOS?

后端 未结 10 1635
日久生厌
日久生厌 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:31

    Since iOS 6.0 you can use NSAttributedString with UIButton.

    //create an underlined attributed string
    NSAttributedString *titleString = [[NSAttributedString alloc] initWithString:@"Title" attributes:@{NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle | NSUnderlinePatternSolid)}];
    
    //use the setAttributedTitle method
    [yourButton setAttributedTitle:titleString forState:UIControlStateNormal];
    

提交回复
热议问题