NSMutableAttributedString的属性NSStrikethroughStyleAttributeName在iOS8中无法正常工作 [英] NSMutableAttributedString's attribute NSStrikethroughStyleAttributeName doesn't work correctly in iOS8

查看:210
本文介绍了NSMutableAttributedString的属性NSStrikethroughStyleAttributeName在iOS8中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不带NSStrikethroughStyleAttributeName属性的可变属性字符串,如下所示:

I have a mutable attributed string without NSStrikethroughStyleAttributeName attribute like this:

NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:@"aaaa" attributes:@{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]}];

和另一个带有NSStrikethroughStyleAttributeName属性的可变属性字符串,如下所示:

and another mutable attributed string with NSStrikethroughStyleAttributeName attribute like this:

NSMutableAttributedString *str2 = [[NSMutableAttributedString alloc] initWithString:@"bbbb"];

以及包含上述两个字符串的整个字符串:

and a whole string containing two strings above:

NSMutableAttributedString *labelString = [[NSMutableAttributedString alloc] init];
[labelString appendAttributedString:str1];
[labelString appendAttributedString:str2];

_label.attributedText = labelString;

它在iOS7和iOS8中都表现良好,如下所示:

It both display well in iOS7 and iOS8, like this:

aaaa bbbb

但当我交换头寸时:

[labelString appendAttributedString:str2];
[labelString appendAttributedString:str1];

它在iOS7中正确显示但在iOS8中没有正确显示

It display correctly in iOS7 but not correctly in iOS8

ios7:bbbb aaaa ios8:bbbbaaaa

ios7: bbbbaaaa ios8: bbbbaaaa

似乎在iOS8中,如果第一个UILabel没有正确渲染删除线属性字符串中的字符不是strikethroughed。
我认为这是iOS8中的一个错误,是否有人遇到过同样的问题?

It seems that in iOS8, UILabel doesn't render the strikethrough correctly if the first character in the attributed string is not strikethroughed. I think this is a bug in iOS8, is there anyone who encounter the same problem with me?

推荐答案

NSMutableAttributedString *str2 = [[NSMutableAttributedString alloc] initWithString:@"bbbb" attributes:@{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone]}];

它应该有帮助

这篇关于NSMutableAttributedString的属性NSStrikethroughStyleAttributeName在iOS8中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆