UITextView 显示特殊字符会导致错误的行高和字号

用相同的代码显示不同的字符顺序的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];
阅读 2.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题