//拼接文本
pragma mark - 封装拼接文本方法
(NSMutableAttributedString *)labAttribute:(NSString *)baseStr
withAddStr:(NSString *)addStr
withBaseStrSize:(int)baseStrSize
withAddStrSize:(int)addStrSize
withBaseColor:(UIColor *)baseColor
withAddColor:(UIColor *)addColor;
{
NSString *string = [NSString stringWithFormat:@"%@%@",baseStr,addStr];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:string];
//两段文本之间有空格baseStr.length
[str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:baseStrSize] range:NSMakeRange(0, baseStr.length)];
[str addAttribute:NSForegroundColorAttributeName value:baseColor range:NSMakeRange(0, baseStr.length)];
[str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:addStrSize] range:NSMakeRange(baseStr.length, addStr.length)];
[str addAttribute:NSForegroundColorAttributeName value:addColor range:NSMakeRange(baseStr.length,addStr.length)];
return str;
}
/**
- 拼接文本
- @param baseStr 前半部分字符串
- @param addStr 后半部分字符串
- @param baseStrSize 前半部分字符串字号大小
- @param addStrSize 后半部分字符串字号大小
- @param baseColor 前半部分字符串颜色
- @param addColor 后半部分字符串颜色
*/
网友评论