要实现如下效果:
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;