Interface Builder
You can use Interface Builder to create a button with any Unicode character in its title. There are several methods.
- As Tommy suggested, you can type Option-P to insert a greek character pi.
- As Tommy also suggested, you can use the Keyboard Viewer from the Input menu to see what characters you can type using the option and control keys. You can also press the on-screen keyboard buttons in the keyboard viewer to insert those characters into the current text field (such as your button's title).
- You can use the Character Viewer Emoji & Symbols window from bottom of the Edit menu (and possibly also the Input menu) to find other characters. Double-clicking a character in Emoji & Symbols will insert it into the current text field. Clicking the icon in the top right of this window toggles between basic and advanced modes.
- You can enable the Unicode Hex Input source (System Preferences > Language & Text > Input Sources) and select it from the Input menu. Then you can hold Option and type four hex digits to enter a Unicode character. For example, you can hold Option and type "03c0" to enter the greek character pi.
- If you find the character somewhere else, like on a web page, you can copy it from the source and then paste it in Interface Builder.
Objective-C
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";
Swift
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}"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…