Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Underline text and color of uibutton in iOS

I have one simple query, i need to underline UIButton text and color. I have under line text for uibutton, however regarding tint color its not working. I have set tint color from xib, its not taking from there.Below is my code.

 NSMutableAttributedString *commentString = [[NSMutableAttributedString alloc] initWithString:@"Testing"];
[commentString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [commentString length])];
[_helpWithLoginLabel setAttributedTitle:commentString forState:UIControlStateNormal];
like image 373
Kashif Avatar asked Oct 08 '13 19:10

Kashif


People also ask

How do you underline text in Swift IOS?

To make the text on UILabel underlined we will need to use the NSMutableAttributedString together with NSUnderlineStyleAttributeName. The Swift code snippet below demonstrates how to create a new UILabel programmatically and then use the NSMutableAttributedString to underline the text on the label.

How do you underline a button title in Swift?

swift 3/4/5 Select button or label title as Attributed. Select range of text which you want to underline. Right click and choose Font then select underline.


1 Answers

In Swift:

let attributes = [NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue]
let attributedText = NSAttributedString(string: button.currentTitle!, attributes: attributes)

button.titleLabel?.attributedText = attributedText
like image 183
ChikabuZ Avatar answered Sep 30 '22 21:09

ChikabuZ