如何在 iOS 中创建不在 Unicode 中的下标字符 [英] How to create subscript characters that's not in Unicode in iOS

查看:19
本文介绍了如何在 iOS 中创建不在 Unicode 中的下标字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了一段时间来创建一个带有下标字符的 NSString 没有成功.甚至可以在 iOS 中执行此操作吗?
我需要一种方法将字符串中的字符更改为下标或上标,但我不能为此使用 Unicode,因为 Unicode 没有所有字母.
我的猜测可能是使用 HTML 标签 但我还没有找到将所述 HTML 标签转换为 NSString 的方法.

I've been trying for a while now to create a NSString with subscripted character without success. Is it even possible to do this in iOS?
I need a way to change characters in a string to subscript or superscript, and I can't use the Unicode for this as Unicode doesn't have all the letters.
My guess could be to use the HTML tags <sub> and <sup> but I haven't find a way to convert said HTML tags to a NSString.

推荐答案

下标和上标不是字符特征.除了少数例外(例如 ²、³、 ª),这是常规字符的呈现方式 - 以较小的字体并在常规字符的基线之上/之下.考虑到这一点,您不能拥有带有下标字符的 NSString",就像您可以拥有带有粗体或斜体字符的 NSString 一样.

Subscript and superscript are not character traits. With few exceptions (e. g. ², ³, ª), this is the way regular characters are rendered - in a smaller font and above/below the regular characters' baseline. With this in mind, you cannot have an "NSString with subscripted characters", no more than you can have an NSString with bold or italic characters.

因此,除非所需的下标字符已经存在于 Unicode 中,否则下标和上标是在字符串渲染时创建的,而不是在字符串创建时创建.这不是 iOS 的限制,这是现代计算机处理字符串方式的限制.

So as a result, unless the desired subscripted character exists in Unicode already, subscript and superscript is created on string rendering, not on string creation. And this is not a limitation of iOS, this is the limitation of the way strings are processed in modern computers.

你对那个 NSString 做了什么?你在 UILabel 上显示它吗?你是通过网络发送的吗?你把它呈现为 HTML 吗?注意 是 HTML 标签;除非 NSString 被专门解释为 HTML(例如,通过 UIWebView),否则它们不会被解释为 sup/superscript.

What do you do to that NSString? Do you display it on a UILabel? Do you send it over the network? Do you render it as HTML? Note that <sub> and <sup> are HTML tags; unless the NSString is interpreted specifically as HTML (say, by a UIWebView), they won't be interpreted as sup/superscript.

这篇关于如何在 iOS 中创建不在 Unicode 中的下标字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆