属性字符串NSMutableAttributedString

要实现如下效果:

 

 NSString * mailString = @"mymail@126.com";
    NSString * mailStringWithQuotes = [NSString stringWithFormat:@"\"%@\"",mailString];
    
    NSRange colorRange = [mailStringWithQuotes rangeOfString:mailStringWithQuotes];
    
    NSMutableAttributedString * attString = [[NSMutableAttributedString alloc] initWithString:mailStringWithQuotes];
    [attString addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:colorRange];
    
    NSRange underLineRange = [mailStringWithQuotes rangeOfString:mailString];
    [attString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:underLineRange];
    
    self.mailLabel.attributedText = attString;

 

posted @ 2014-06-25 11:44  Dadada胖纸er  阅读(183)  评论(0编辑  收藏  举报