Monday, January 6, 2014

How to get Underlined text attributeString Like set on email label, Multiple Colors on label

#pragma mark ==== Underlined text attributeString too set on email, addres labels =====
+(NSMutableAttributedString *)underLinedText :(NSString *)normalString
{
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:normalString];
    [attributeString addAttribute:NSUnderlineStyleAttributeName
                            value:[NSNumber numberWithInt:1]
                            range:(NSRange){0,[attributeString length]}];
    
    return attributeString;

}

//To use this attributeString

  textLabel.attributedText = [Self underLinedText: @"http://www.gmail.com"] ;


For Multiple Color Use


 [attributeString addAttribute:
NSForegroundColorAttributeName 

                                  value: [UIColor redColor] 
                                  range: NSMakeRange(10, 1)];

No comments:

Post a Comment