I need to make subscripts for chemistry formulas (H2O, Na^2+, etc)?
Is this possible to do with NSAttributedString, or is there an alternative/easier way to make subscripts?
This is possible to do with NSAttributedString
. The attribute constant you're looking for depends on your platform. For Mac OS X it is NSSuperscriptAttributeName
and on iOS it is kCTSuperscriptAttributeName
. Pass in a negative value for subscript.
The only caveat is that UILabel
on iOS can't draw NSAttributedString
s (yet, fingers crossed for iOS 6). You would need to draw the text using Core Text or find some third party replacement for UILabel
that can draw an NSAttributedString
.