Add Underline to a Label in IOS Application

In iOS 6.0 UILabel supports NSAttributedString, which can be used to underline a Label Programatically.

Use the below code to add underline to a label

    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@"This is an underlined text"];
    [attributeString addAttribute:NSUnderlineStyleAttributeName
                            value:[NSNumber numberWithInt:1]
                            range:(NSRange){0,[attributeString length]}];


Now assign the attribute to the label

   yourLabel.attributedText = [attributeString copy];


Sharing is caring!

Related Posts

Leave a Comment

DON’T MISS OUR GIVEAWAYS!
Subscribe To Newsletter
Subscribe to our newsletter and get all the latest updates offers and giveaways right in your inbox.
Subscribe
Give it a try, you can unsubscribe anytime.
close-link

Join Free Giveaway!

Subscribe to our newsletter to get latest offers and giveaways!
SUBSCRIBE
close-link
shares