英文好的直接上原文:http://stackoverflow.com/questions/26136157/underline-part-of-a-string-using-nsmutableattributedstring-in-ios8-is-not-workin
问题:在iOS8.1上(8.4不存在,估计苹果已修复),NSMutableAttributedString(NSAttributedString也一样),如果有2段string,第二段使用删除线效果(NSUnderlineStyleSingle)会无效。
解决方法:第一段string设置NSStrikethroughStyleAttributeName为NSUnderlineStyleSingle
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init];
[attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"test "
attributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleNone)}]];
[attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"s"
attributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
NSBackgroundColorAttributeName: [UIColor clearColor]}]];
[attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"tring"]];