本文介绍了上级/下标在iOS13中似乎已损坏(NSAttributedString)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS13中尝试使用UITextView中的NSAttributedString显示上级/下标文本似乎已损坏-除非有人知道否则如此?

Trying to display super/subscript text using NSAttributedString in a UITextView seems broken in iOS13 - unless anyone knows otherwise?

奇怪的是,如果我使用UIFont systemFont,那么它可以工作-但是,如果我使用任何其他字体,则不能.

Curiously if I use the UIFont systemFont then it works - but if I use any other font it doesn't.

有关在我的测试应用中设置UITextView的代码,请参见下文.

See below for my code to setup a UITextView in my test app.

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIFont* font = [UIFont systemFontOfSize:32];
    //UIFont* font = [UIFont fontWithName:@"Helvetica Neue" size:32];
    //UIFont* font = [UIFont fontWithName:@"Courier" size:32];
    //UIFont* font = [UIFont fontWithName:@"Arial" size:32];

    NSMutableAttributedString* as = [[NSMutableAttributedString alloc] initWithString:@"Super2Script" attributes:@{NSFontAttributeName : font}];

    [as addAttribute:(NSString*)kCTSuperscriptAttributeName value:@(1) range:NSMakeRange(5, 1)];



    UITextView* tv = [[UITextView alloc] initWithFrame:CGRectZero];
    tv.attributedText = as;
    [tv sizeToFit];

    [self.view addSubview:tv];
    tv.center = CGPointMake(self.view.bounds.size.width / 2, self.view.bounds.size.height / 2);
}

推荐答案

为此简单的修复".

似乎kCTSuperscriptAttributeName在iOS13中不再起作用(对于非系统字体.)您需要改用NSSuperscriptAttributeName.不知道它的定义在哪里(哪个标头),因此所需的实际字符串值是"NSSuperScript"

It appears kCTSuperscriptAttributeName no longer works in iOS13 (for non-system fonts.) You need to use NSSuperscriptAttributeName instead. No idea where the definition for this lives (which header) so the actual string value required is "NSSuperScript"

这篇关于上级/下标在iOS13中似乎已损坏(NSAttributedString)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 01:08