techrounder-default

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


Previous Post
techrounder-default

Javascript to extract last parameter of a string after slash(/)

Next Post
placeholder-techrouner

How to Use Hex Color Codes in Objective C with UIColor

Add a comment

Leave a Reply

Your email address will not be published. Required fields are marked *