【问题标题】:adding a superscript or subscript to a button title using the interface builder in Xcode 8使用 Xcode 8 中的界面构建器为按钮标题添加上标或下标
【发布时间】:2017-09-17 17:44:34
【问题描述】:

我想创建一个标题为 x 平方的按钮,但我找不到任何有关如何向 x 添加上标的信息。我能找到的只是如何在页面或单词中创建下标和上标。我不想复制和粘贴。有没有办法使用 Xcode 中的界面生成器来做到这一点?

【问题讨论】:

    标签: ios unicode uibutton interface-builder xcode8


    【解决方案1】:

    x²

    在Storyboard中实现上标二的唯一方法就是直接粘贴。 unicode 字符代码为U+00B2。

    这就是它在 Bar Button 项目中时的样子。

    很遗憾,仍然无法从 macOS 排版面板启用 OpenType 功能并将其应用到 Storyboard 元素。

    幸运的是,U+00B2 是真正的上标/上标版本,而不是可以在 TextEdit 或 Pages 菜单(格式 > 字体 > 基线 > 上标)中调用的虚假版本。

    您可以在 Stack Overflow 上找到许多关于如何创建假字体的示例 — 通过减小字体大小和提高基线。这是完全错误的做法。避免它。

    如果您想通过代码实现该功能,这里是系统字体的方法:

    let systemFontDescriptor = UIFont.systemFont(ofSize: 15.0).fontDescriptor
    let superscriptFontDescriptor = systemFontDescriptor.addingAttributes(
        [
            UIFontDescriptorFeatureSettingsAttribute: [
                [
                    UIFontFeatureTypeIdentifierKey: kVerticalPositionType,
                    UIFontFeatureSelectorIdentifierKey: kSuperiorsSelector,
                ],
            ]
        ]
    )
    button.font = UIFont(descriptor: superscriptFontDescriptor, size: 0.0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-22
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多