如何使用小帽?

时间:2016-04-15 14:41:13

标签: swift uikit uifont

我正在尝试使用具有小型大写字母的字体。我在某个人的网站上发现了一个UIFont扩展,声称它可以做小帽,但唉,没有运气。有什么想法吗?

@Override
public void visitNode(Tree tree) {
    CallExpressionTree callExpression = (CallExpressionTree) tree;

    if (callExpression.callee().is(Kind.DOT_MEMBER_EXPRESSION)) {
        DotMemberExpressionTree callee = (DotMemberExpressionTree) callExpression.callee();

        // get the file that is checked
        File toTestedFile = getContext().getFile();

        //how to get the project path here to get the relative path???

        if (isCalleeConsoleLogging(callee)) {
            addLineIssue(tree, MESSAGE);
        }
    }

}

1 个答案:

答案 0 :(得分:2)

问题是很少有字体拥有小型大写字母。如果您没有使用其中的少数几个,那么您将无法获得小额上限。你不能神奇地创造一个不存在的功能......

此处访问Didot的小型大写字母的代码:

    let desc = UIFontDescriptor(name:"Didot", size:18)
    let d = [
        UIFontFeatureTypeIdentifierKey:kLetterCaseType,
        UIFontFeatureSelectorIdentifierKey:kSmallCapsSelector
    ]
    let desc2 = desc.fontDescriptorByAddingAttributes(
        [UIFontDescriptorFeatureSettingsAttribute:[d]]
    )
    let f = UIFont(descriptor: desc2, size: 0)

现在f是Didot的小型大写字母,您可以在界面中使用它。

如果您使用的字体不是Didot,请将其替换为该代码;但请务必先确定您的字体有一个小型大写字母,否则这不会起作用。