NSMutableAttributedString 处理字符串里需要有特殊颜色或者大小

 UILabel* contentLabel =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 255, 0)];

    contentLabel.numberOfLines =0;

    NSMutableAttributedString* attString =[[NSMutableAttributedString alloc]initWithString:contentStr];

    [attString addAttribute:NSForegroundColorAttributeName value:kCrownColor range:NSMakeRange(0, onelenght)];

    [attString addAttribute:NSForegroundColorAttributeName value:kCoffeeColor range:NSMakeRange(onelenght+1, 2)];

    [attString addAttribute:NSForegroundColorAttributeName value:kCrownColor range:NSMakeRange(threelenght , twolenght)];

    [attString addAttribute:NSForegroundColorAttributeName value:kCoffeeColor range:NSMakeRange(twolenght+onelenght+5 , atcontent.length+1)];

    [attString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:15] range:NSMakeRange(0, contentStr.length)];

    contentLabel.attributedText =attString;

    contentLabel.backgroundColor =[UIColor clearColor];

    contentLabel.lineBreakMode =NSLineBreakByWordWrapping;

    contentLabel.contentMode =UIViewContentModeCenter;

    [contentLabel sizeToFit];

    [contentLabel setFrame:CGRectMake(5, 0, 255, contentLabel.frame.size.height+8)];

    [cell addSubview:contentLabel];

你可能感兴趣的:(2014)