-(NSAttributedString*)attributeWith:(NSString*)first second:(NSString*)second{//添加中划线,文字颜色
NSRange range1 = NSMakeRange(0, first.length);
NSRange range2 = NSMakeRange(first.length+1, second.length-2);
NSMutableAttributedString* astring = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",first,second]];
NSDictionary* attributes = @{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle),NSStrikethroughColorAttributeName:[UIColor orangeColor],NSForegroundColorAttributeName:[UIColor blackColor] };
[astring addAttributes:attributes range:range2];
[astring addAttribute:NSStrikethroughStyleAttributeName value:@( NSUnderlineStyleNone) range:range1];//
// NSRange range = NSMakeRange(0, astring.length);
[astring addAttribute:NSForegroundColorAttributeName value:YRedColor range:range1];//
return astring;
}
本文介绍如何使用 Objective-C 编程语言为 NSAttributedString 添加中划线及文本颜色属性,包括不同部分文字的颜色设置和中划线样式的实现。
610

被折叠的 条评论
为什么被折叠?



