【问题标题】:How to display superscript for third power/cube characters as a string in UILabel?如何在 UILabel 中将三次方/立方字符的上标显示为字符串?
【发布时间】:2011-12-06 11:54:10
【问题描述】:

我正在尝试寻找解决方案,但我很困惑如何在 UILabel 中显示第三次幂/立方体。我试图在以前提出的问题中找到答案,但没有一个有用。

我试图得到答案的问题:

how-to-show-superscript-for-registered-symbol

UILabel and superscript

如果我必须使用 unichars,我该如何将它们用于上标??

谢谢..

【问题讨论】:

    标签: iphone objective-c ios ipad


    【解决方案1】:

    您需要为上标三个包含 unicode 符号:

    NSInteger number = 10;
    NSString *cubedSymbol = @"\u00B3";
    NSString *tenCubed = [NSString stringWithFormat:@"%d%@",number,cubedSymbol];
    

    还有更多乐趣here

    【讨论】:

    • nice :)...不断增加“\u00B3”中的数字以获得其他数字上标...例如,对于平方,“\u00B2”...这很棒! !
    【解决方案2】:

    另一种解决方案是使用 Core Text 框架在要制作上标的字符串部分上绘制带有 kCTSuperscriptAttributeName 属性的 NSAttributedString。这最终需要更多的工作,包括自定义绘图和其他东西,但比依赖 unicode 字符更灵活。

    这是我找到的包含更多信息的博文:http://iphonedevelopment.blogspot.com/2011/03/attributed-strings-in-ios.html

    Mac OS X 上的NSAttributedString 在 AppKit 中内置了许多不错的用途,但 Apple 并没有让 iOS 的 UIKit 变得简单。

    【讨论】:

    • 1.您需要导入 CoreText/CoreText.h ---- 2. 您需要添加 CoreText 框架 ---- 3. 您需要知道属性的值(未在此答案中列出)。不是一个好的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多