带Core Text iPhone的上标,下标文本 [英] Superscript, Subscript text with Core Text iPhone

查看:42
本文介绍了带Core Text iPhone的上标,下标文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释一下,如何用Core Text绘制上标和下标字母吗?

Can anyone explain me, How to draw superscript and subscript alphabets with Core Text?

谢谢.

推荐答案

我注意到这个问题有点老了,希望您在此问题上仍然需要帮助,并且这篇帖子会对您有所帮助.

I noticed that this question is a bit old, I hope you still require assistance in this matter and that this post will help you.

您可以使用NSAttributedString(或其可变的对等NSMutableAttributedString)将不同的属性(例如字体,名称和大小)分配给单个字符串的特定范围.

you can use NSAttributedString (or its mutable counterpart NSMutableAttributedString) to assign different attributes (such as font, both name and size) to specific ranges of a single string.

核心文本本身不支持上标和下标,为使它们看起来不错,您可能需要做很多工作.幸运的是,有一个由Oliver Drobnik从可可遗传学开发的开源项目,它使您可以轻松地将HTML转换为NSAttributedString(或NSMutableAttributedString),将其输入到自定义文本视图中,并在其上显示上标和下标(以及许多其他HTML和CSS)将出现在UIWebview中,但无需使用UIWebview.您可以从此处下载该项目.

Superscript and subscript are not natively supported by core text and to make them look good you might need to do quite a lot of work. Fortunately there is an open source project developed by Oliver Drobnik from cocoa genetics that allows you to easily convert HTML into NSAttributedString (or NSMutableAttributedString), feed it into a custom textview and show superscripts and subscripts (along with many other HTML and CSS) as they would appear in a UIWebview, but without the need to use a UIWebview. You can download the project from here.

尽管在此项目中付出了很多努力,但有两个警告:

While a lot of effort has been put into this project, there are two caveats:

  1. 计算有时可能会非常耗费性能.
  2. 尚不支持所有HTML标记和CSS功能.

这篇关于带Core Text iPhone的上标,下标文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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