同一个label中间几个字 变颜色、大小都能改变

#pragma mark 同一个label中间几个字 变颜色、大小都能改变

//用法:self.integralLabel.attributedText =[NSString getLabelChangeColor:[UIColor orangeColor] andFont:[UIFont systemFontOfSize:22] andString1:@"我的" andChangeString:@"大的" andGetstring3:@"自己"];

+(NSMutableAttributedString*)getLabelChangeColor:(UIColor*)color andFont:(UIFont*)fout andString1:(NSString*)string1 andChangeString:(NSString*)string2 andGetstring3:(NSString*)string3{

//string2 是变色的部分

NSString *inteStr = [NSString stringWithFormat:@"%@%@%@",string1,string2,string3];

NSMutableAttributedString *inteMutStr = [[NSMutableAttributedString alloc] initWithString:inteStr];

//设置中间变红的字体大小颜色

NSRange orangeRange = NSMakeRange([[inteMutStr string] rangeOfString:string2].location, [[inteMutStr string] rangeOfString:string2].length);

[inteMutStr addAttributes:@{NSFontAttributeName:fout,NSForegroundColorAttributeName:color} range:orangeRange];

return inteMutStr;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 字体属性设置示例:if(color ==nil) {color = [NSColor redColor];}NSF...
    袏扌戒指阅读 8,497评论 0 2
  • 与NSString类似,在iOS中AttributedString也分为NSAttributedString和 N...
    钱十六阅读 904评论 0 0
  • 自己封装的工具类一、NSString类型//手机号码验证+(BOOL)phoneText:(NSString*)s...
    爱恨的潮汐阅读 910评论 0 1
  • 年年岁岁花相似,岁岁年年人不同。 又是一年高考季,万般感慨涌心头。昨日看到朋友发的状态,清一色的“爱心送考车”在考...
    尚武三宝阅读 467评论 0 0
  • 黍离 彼黍离离,彼稷之苗。行迈靡靡,中心摇摇。 知我者,谓我心忧;不知我者,谓我何求。悠悠苍天,此何人哉? 彼黍离...
    OLYmpcs阅读 549评论 0 0

友情链接更多精彩内容