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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is possible to do with
NSAttributedString. The attribute constant you’re looking for depends on your platform. For Mac OS X it isNSSuperscriptAttributeNameand on iOS it iskCTSuperscriptAttributeName. Pass in a negative value for subscript.The only caveat is that
UILabelon iOS can’t drawNSAttributedStrings (yet, fingers crossed for iOS 6). You would need to draw the text using Core Text or find some third party replacement forUILabelthat can draw anNSAttributedString.