Rumah > Soal Jawab > teks badan
用相同的代码显示不同的字符顺序的NSMutableAttributedString,会导致行高和字号的BUG。
▲●■▲●■▲●■*asdf
●▲■▲●■▲●■*asdf
■●■▲●■▲●■*asdf
最后两行是仅第一个字符和仅○设置Attributes,可以看出会影响后面没有设置的字符
code
NSMutableAttributedString *symbol = [[NSMutableAttributedString alloc] initWithString:@"●▲■▲●■▲●■*asdf"];
UIFont *symbolFont = [UIFont systemFontOfSize:24.0];
UIColor *stripesPurple = [UIColor colorWithRed:0.83 green:0.64 blue:0.83 alpha:1];
[symbol addAttributes:@{NSForegroundColorAttributeName:[UIColor purpleColor],
NSFontAttributeName:symbolFont,
NSStrokeWidthAttributeName:@-4,
NSStrokeColorAttributeName:[UIColor purpleColor]}
range:NSMakeRange(0, 3)];
[symbol addAttributes:@{NSForegroundColorAttributeName:stripesPurple,
NSFontAttributeName:symbolFont,
NSStrokeWidthAttributeName:@-4,
NSStrokeColorAttributeName:[UIColor purpleColor]}
range:NSMakeRange(3, 3)];
[symbol addAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
NSFontAttributeName:symbolFont,
NSStrokeWidthAttributeName:@-4,
NSStrokeColorAttributeName:[UIColor purpleColor]}
range:NSMakeRange(6, 3)];
//[self.myTextView setAttributedText:symbol];
[self.attrLabel setAttributedText:symbol];