您的位置:首页 > 其它

多个字符串拼接

2016-06-24 18:04 387 查看
+(NSMutableAttributedString *)getNewStringWithString:(NSMutableArray *)StrArr AndColor:(NSMutableArray*)ColorArr

{

    NSMutableAttributedString * AttStr1;

    if (StrArr.count>0&&ColorArr.count>0) {

        NSString * str1 = [StrArr
objectAtIndex:0];

        NSRange r = [str1
rangeOfString:str1];

        AttStr1 =   [[NSMutableAttributedString
alloc]initWithString:str1];

        [AttStr1 addAttribute:NSForegroundColorAttributeName
value:[PublicClass
colorFromHexRGB:ColorArr[0]]
range:NSMakeRange(0, r.length)];

        for (int i=1; i<(StrArr.count>ColorArr.count?ColorArr.count:StrArr.count);
i++) {

            NSString * str2 = [StrArr
objectAtIndex:i];

            NSRange str2r = [str2
rangeOfString:str2];

            NSMutableAttributedString * AttStr2 =   [[NSMutableAttributedString
alloc]initWithString:str2];

            [AttStr2 addAttribute:NSForegroundColorAttributeName
value:[PublicClass
colorFromHexRGB:ColorArr[i]]
range:NSMakeRange(0, str2r.length)];

            [AttStr1 appendAttributedString:AttStr2];

        }

    }

    return AttStr1;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: