How to use NSSuperscriptAttributeName for OS X

人走茶凉 提交于 2019-12-08 09:31:31

问题


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.


回答1:


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)])


来源:https://stackoverflow.com/questions/30059724/how-to-use-nssuperscriptattributename-for-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!