Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underlining a certain portion of a UILabel

Tags:

ios

uilabel

I need to underline a certain portion of a UILabel as the title suggests. For example: Please click ESPNSoccernet to read the latest Football News. I would like to underline the word ESPNSoccernet. This is because I want it to be clickable and it need to link to the website.

Need some guidance on doing this. If there is another way, do tell me...

like image 890
lakshmen Avatar asked May 13 '13 10:05

lakshmen


1 Answers

for ios 6, you can use AttributedStrings

NSMutableAttributedString *yourString = [[NSMutableAttributedString alloc] initWithString:@"Please click ESPNSoccernet to read the latest Football News."];
[yourString addAttribute:NSUnderlineStyleAttributeName
                        value:[NSNumber numberWithInt:1]
                        range:(NSRange){0,25}];

label.attributedText = [yourString copy];

you can also use a 3rd party UILable library TTTAttributedLabel.

like image 119
Bonnie Avatar answered Sep 18 '22 03:09

Bonnie