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

 上善若水纯_310 发布于 2022-10-29 07:14

用相同的代码显示不同的字符顺序的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];
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有