Swift改变UILabel字体样式方法

Swift改变UILabel字体样式方法

2023年7月14日发(作者:)

Swift改变UILabel字体样式⽅法Swift 版//text:要改变的字//result:整个label⾥的字//color: 字的颜⾊///富⽂本,根据⽂字改变字体颜⾊func changeSomeTextColor(text: String, inText result: String, color: UIColor) -> NSAttributedString { let attributeStr = NSMutableAttributedString(string: result) let colorRange = NSMakeRange((of: text).location, (of: text).length) ribute(NSForegroundColorAttributeName, value:color , range: colorRange) return attributeStr}OC版//str:要改变的字

//result:整个label⾥的字

//color: 字的颜⾊- (NSMutableAttributedString *)changeSomeText:(NSString *)str inText:(NSString *)result withColor:(UIColor *)color { NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:result]; NSRange colorRange = NSMakeRange([[attributeStr string] rangeOfString:str].location,[[attributeStr string] rangeOfString:str].length); [attributeStr addAttribute:NSForegroundColorAttributeName value:color range:colorRange]; return attributeStr;}效果:

备注(样式)1.中间横划线 NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};

发布者:admin,转转请注明出处:http://www.yc00.com/news/1689265746a226480.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信