Interface constructor
You can use Interface Builder to create a button with any Unicode character in its name. There are several methods.
- As Tommy suggested, you can enter Option-P to insert the Greek pi symbol.
- As Tommy also suggested, you can use the keyboard viewer from the Login menu to find out which characters you can enter using the option and control keys. You can also press the buttons on the on-screen keyboard in the keyboard viewer to insert these characters into the current text box (for example, the name of your button).
- You can use the
Symbol Viewer Emoji and Symbols window from the bottom of the Edit menu (and possibly also the Input menu) to find other symbols. Double-clicking a character in Emoji and Symbols inserts it into the current text box. Clicking the icon in the upper right corner of this window toggles the basic and advanced modes. - You can turn on the Unicode Hex input source (System Settings> Language and Text> Input Sources) and select it in the "Input" menu. You can then hold down the option and type four hexadecimal digits to enter the Unicode character. For example, you can hold the option and enter "03c0" to enter the Greek character pi.
- If you find the symbol elsewhere, such as on a web page , you can copy it from the source and then paste it into Interface Builder.
Objective-c
If you want to set the button name in Objective-C, it looks like this:
self.myButton.titleLabel.text = @"π or \u03c0";
You can enter Unicode characters directly into the source code using any of the methods listed above, or you can use the Unicode \u escape sequence and then four hexadecimal digits.
Characters outside the Unicode 0 plane (base multilingual plane or BMP) require more than four hexadecimal digits. For them, use \u and then eight hexadecimal digits. Example:
self.myButton.titleLabel.text = @"💖 or \U0001f496";
Swift
If you want to set the name of the button in Swift, it looks like this:
myButton.titleLabel.text = "π or \u{3c0}"
In Swift unicode escape sequences, one to eight hexadecimal digits are allowed inside curly braces, so it has the same syntax for a character outside BMP:
myButton.titleLabel.text = "💖 or \u{1f496}"
rob mayoff Jan 18 '12 at 21:20 2012-01-18 21:20
source share