用相同的代碼顯示不同的字符順序的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];
學習是最好的投資!