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];


Leave a Comment

We would like to show you notifications for the latest offers and updates.
Dismiss
Allow Notifications