iOS14 上 UILabel 中显示的 NSAttributedString 错误
NSAttributedString displayed in UILabel wrong on iOS14
具有某些属性的 NSMutableAttributedString 在 iOS 12 之前已正确显示在 UILabel 中,但 wrong/different 在 iOS 14:
字符串 "bukskin" 有两个红色字母,最后 4 个字母有下划线,正确 iOS 12:
在 iOS 14 上,下划线超出单词末尾大约两个字母。这似乎只有在下划线位于字符串末尾时才会发生:
iOS 12 和 iOS 14 的字符串属性转储看起来相同,但字符串在 iOS 14 的 UILabel 屏幕上显示不同。我错过了吗什么东西?
转储 iOS 12(使用 enumerateAttributesInRange):
word=bukskin attributed_word=b{
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 0;
}uk{
NSColor = "UIExtendedGrayColorSpace 0 1";
NSLigature = 0;
NSUnderline = 0;
}s{
NSColor = "UIExtendedGrayColorSpace 0 1";
NSLigature = 0;
NSUnderline = 1;
}k{
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 1;
}in{
NSColor = "UIExtendedGrayColorSpace 0 1";
NSLigature = 0;
NSUnderline = 1;
} attrs={
NSColor = "UIExtendedGrayColorSpace 0 1";
NSLigature = 0;
NSUnderline = 1;
}
iOS14 的转储:
word=bukskin attributed_word=b{
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 0;
}uk{
NSColor = "<UIDynamicSystemColor: 0x600003682440; name = labelColor>";
NSLigature = 0;
NSUnderline = 0;
}s{
NSColor = "<UIDynamicSystemColor: 0x600003682440; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
}k{
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 1;
}in{
NSColor = "<UIDynamicSystemColor: 0x600003682440; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
} attrs={
NSColor = "<UIDynamicSystemColor: 0x600003682440; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
}
Tarun Tyagi 评论中的 link 暗示了一个修复:将整个属性字符串的基线偏移设置为 0。这似乎有效。初始化后我现在做:
[att_word addAttribute:NSBaselineOffsetAttributeName value:[NSNumber numberWithInt:0] range:NSMakeRange(0, att_word.length)];
我会向 Apple 提交错误。
现在的属性转储是:
word=bukskin attributed_word=b{
NSBaselineOffset = 0;
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 0;
}uk{
NSBaselineOffset = 0;
NSColor = "<UIDynamicSystemColor: 0x600000506f00; name = labelColor>";
NSLigature = 0;
NSUnderline = 0;
}s{
NSBaselineOffset = 0;
NSColor = "<UIDynamicSystemColor: 0x600000506f00; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
}k{
NSBaselineOffset = 0;
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 1;
}in{
NSBaselineOffset = 0;
NSColor = "<UIDynamicSystemColor: 0x600000506f00; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
} attrs={
NSBaselineOffset = 0;
NSColor = "<UIDynamicSystemColor: 0x600000506f00; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
}
具有某些属性的 NSMutableAttributedString 在 iOS 12 之前已正确显示在 UILabel 中,但 wrong/different 在 iOS 14:
字符串 "bukskin" 有两个红色字母,最后 4 个字母有下划线,正确 iOS 12:
在 iOS 14 上,下划线超出单词末尾大约两个字母。这似乎只有在下划线位于字符串末尾时才会发生:
iOS 12 和 iOS 14 的字符串属性转储看起来相同,但字符串在 iOS 14 的 UILabel 屏幕上显示不同。我错过了吗什么东西?
转储 iOS 12(使用 enumerateAttributesInRange):
word=bukskin attributed_word=b{
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 0;
}uk{
NSColor = "UIExtendedGrayColorSpace 0 1";
NSLigature = 0;
NSUnderline = 0;
}s{
NSColor = "UIExtendedGrayColorSpace 0 1";
NSLigature = 0;
NSUnderline = 1;
}k{
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 1;
}in{
NSColor = "UIExtendedGrayColorSpace 0 1";
NSLigature = 0;
NSUnderline = 1;
} attrs={
NSColor = "UIExtendedGrayColorSpace 0 1";
NSLigature = 0;
NSUnderline = 1;
}
iOS14 的转储:
word=bukskin attributed_word=b{
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 0;
}uk{
NSColor = "<UIDynamicSystemColor: 0x600003682440; name = labelColor>";
NSLigature = 0;
NSUnderline = 0;
}s{
NSColor = "<UIDynamicSystemColor: 0x600003682440; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
}k{
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 1;
}in{
NSColor = "<UIDynamicSystemColor: 0x600003682440; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
} attrs={
NSColor = "<UIDynamicSystemColor: 0x600003682440; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
}
Tarun Tyagi 评论中的 link 暗示了一个修复:将整个属性字符串的基线偏移设置为 0。这似乎有效。初始化后我现在做:
[att_word addAttribute:NSBaselineOffsetAttributeName value:[NSNumber numberWithInt:0] range:NSMakeRange(0, att_word.length)];
我会向 Apple 提交错误。
现在的属性转储是:
word=bukskin attributed_word=b{
NSBaselineOffset = 0;
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 0;
}uk{
NSBaselineOffset = 0;
NSColor = "<UIDynamicSystemColor: 0x600000506f00; name = labelColor>";
NSLigature = 0;
NSUnderline = 0;
}s{
NSBaselineOffset = 0;
NSColor = "<UIDynamicSystemColor: 0x600000506f00; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
}k{
NSBaselineOffset = 0;
NSColor = "UIExtendedSRGBColorSpace 0.8125 0 0 1";
NSLigature = 0;
NSUnderline = 1;
}in{
NSBaselineOffset = 0;
NSColor = "<UIDynamicSystemColor: 0x600000506f00; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
} attrs={
NSBaselineOffset = 0;
NSColor = "<UIDynamicSystemColor: 0x600000506f00; name = labelColor>";
NSLigature = 0;
NSUnderline = 1;
}