问题
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