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条)