如何在 OS X 中使用 NSSuperscriptAttributeName [英] How to use NSSuperscriptAttributeName for OS X
本文介绍了如何在 OS X 中使用 NSSuperscriptAttributeName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以更改字体和大小,但我坚持将文本设为上标.
I can change the font and size but I'm stuck with making text a superscript.
这是我的字体和大小的工作代码:
Here is my working code for font and size:
aVerseMutableString = NSMutableAttributedString(string: book.verseText,
attributes: [NSFontAttributeName:NSFont(name: "Helvetica", size: 18.0)!])
这是我正在尝试的上标不起作用的方法:
Here is what I'm trying for superscript that's not working:
aVerseNumberMutableString = NSMutableAttributedString(string: verseNumber.description,
attributes: [NSSuperscriptAttributeName:NSNumber(1)!])
我不知道如何做属性部分来创建上标.
I'm not sure how to do the attributes part to create a superscript.
推荐答案
在使用 NSBaselineOffsetAttributeName 之后,我想出了如何按照上面显示的方式进行操作.两种方式都有:
After using NSBaselineOffsetAttributeName I figured out how to do it the way I showed above. Here are both ways:
NSSuperscriptAttributeName
aVerseNumberMutableString = NSMutableAttributedString(string: verseNumber.description,
attributes: [NSSuperscriptAttributeName:NSNumber(int: 2)])
NSBaselineOffsetAttributeName
aVerseNumberMutableString = NSMutableAttributedString(string: verseNumber.description,
attributes: [NSBaselineOffsetAttributeName:NSNumber(double: 2.0)])
这篇关于如何在 OS X 中使用 NSSuperscriptAttributeName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文