我在iOS 7中有一个奇怪的bug,我称它为“fi bug”。
摘要:
这两个字"fi“被认为是一个字符。
解释:
我创建了一个UILabel,其中包含一个单词,作为一个属性文本。我创建了一个函数,在单击颜色时,这个单词的一个字符是蓝色的。(也就是说,首先单击它为第一个字符着色,然后单击它从第一个到第二个…)。
使用iOS 6模拟器一点问题都没有,当我们切换到iOS 7模拟器时,只要单词中不包含"fi“,一切都没问题。例如,当我写“金融”时,从第一次点击f和我都是蓝色的。
它不取决于'fi‘的立场,似乎只有'fi’有问题。
代码:
UILabel:
@property (strong, nonatomic) IBOutlet UILabel *wordLabel;
着色函数:
- (void) changeWordLabelWithWord:( NSString *)word to:(int) position{
NSMutableAttributedString *coloredText = [[NSMutableAttributedString alloc] initWithString:word];
[coloredText addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.25 green:0.66 blue:0.96 alpha:1] range:NSMakeRange(0,position)];
_wordLabel.attributedText = coloredText;
}谢谢你的帮助和洞察力。
干杯!
发布于 2014-01-26 21:31:58
您可以在NSMutableAttributedString上将“结扎”属性设置为零。来自documentation
NSLigatureAttributeName此属性的值是一个包含整数的NSNumber对象。连接将使用与这些字符相对应的单个自定义字形来呈现特定的字符组合。值0表示没有连接。值1表示默认连接的使用。值2表示所有连接线的使用。此属性的默认值为1。(iOS不支持值2)。
使用默认值1,字母"fi“呈现为一个字形。有些字体甚至有三个字符序列的连接,如"ffl“。
发布于 2014-01-26 21:32:09
iOS 7增加了许多排版细节。其中之一是连接:操作系统用更好的字形(字符)变体代替一些字符序列。
发布于 2014-04-19 12:04:35
这是你能解决这个问题的方法。iOS 6.0+
NSMutableAttributedString *attributedString;
attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
[attributedString addAttribute:NSLigatureAttributeName value:@0 range:NSMakeRange(0, label.text.length)];
[label.text setAttributedText:attributedString];
[attributedString release];https://stackoverflow.com/questions/21369439
复制相似问题