I am creating a calculator for iPhone (for practice) and I want to use the symbol x^2 without the ^ so that 2 appears directly above x. Is there a way to achieve this?
It would also be good to have an x symbol that is a bit “stylish” like the ones used in latex (e.g. such as this)
I am using iOS 5, XCode 4.2
I guess you mean you want to display x² in a label or button.
The easiest way is to use Unicode character U+00B2, SUPERSCRIPT TWO, which is what I did.
In Objective-C, you can put any 16-bit Unicode character in a string using a
\uescape:If you want to set it in Interface Builder, you can use the Character Viewer to insert it.
Unicode also has character U+1D465 MATHEMATICAL ITALIC SMALL X. You can use
\U0001D465in a string to represent that character. Unfortunately, iOS doesn’t seem to support displaying that character (in my test on the iOS 5.0 simulator).So if you want the
xto use an italic font but the2to use a regular font, you will need to use separate labels for thexand the2, or use Core Text to render an attributed string containing both characters with appropriate attributes. As of iOS 5.1, no UIKit classes support drawing attributed strings.