拼接文本

2016-10-18  本文已影响24人  HuLL乐乐

//拼接文本

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;

}
/**

上一篇下一篇

猜你喜欢

热点阅读