I'm trying to display the greek letter pi (unicode \u03C0) on a button as the title. When I try to set the title using drag'n'drop graphical editor, the word "\u03C0" shows. Is there some way to set unicode text in the graphical editor, or do I need to do it programmatically? If I have to do it programmatically, what is the best way to do this?
I hope somebody can help me with this, since my google searches have been futile.
I use iOS 5.0 XCode version 4.2.1
You can use Interface Builder to create a button with any Unicode character in its title. There are several methods.
If you want to set the button's title in Objective-C, it looks like this:
self.myButton.titleLabel.text = @"Ï€ or \u03c0";
You can type Unicode characters right into your source code using any of the methods I listed above, or you can use a Unicode escape sequence of \u
followed by four hex digits.
Characters outside of Unicode plane 0 (the Basic Multilingual Plane, or BMP) require more than four hex digits. For them, use \U
followed by eight hex digits. Example:
self.myButton.titleLabel.text = @"💖 or \U0001f496";
If you want to set the button's title in Swift, it looks like this:
myButton.titleLabel.text = "Ï€ or \u{3c0}"
The Swift unicode escape sequence allows from one to eight hexidecimal digits inside the braces, so it's the same syntax for a character outside the BMP:
myButton.titleLabel.text = "💖 or \u{1f496}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With