UILabel, UIFont and UTF-8 Triangle
Based on:
Unicode characters being drawn differently in iOS5
iOS 6 supports Unicode 6.1's variation selector, in this case \U0000FE0E
. To answer my own question:
@"\U000025B6" // a fancy triangle (mapped to Emoji)
@"\U000025B6\U0000FE0E" // black right-pointing triangle
For more information check: http://www.unicode.org/versions/Unicode6.1.0/
Thanks @martin-r and @ACB, I wouldn't be able to figure this out without your hints!
Getting a normal looking unicode down arrow in a UILabel like this ⬇
Displaying some characters as "Emojis" is a feature which is e.g. (controversially) discussed here: https://devforums.apple.com/message/487463#487463 (requires Apple Developer login). This feature was introduced in iOS 6.
A solution (from https://stackoverflow.com/a/13836045/1187415) is to append the Unicode "Variation selector" U+FE0E, e.g.
self.myLabel.text = @"\u2B07\uFE0E";
// or:
self.myLabel.text = @"⬇\uFE0E";
Note that on iOS <= 5.x, the Variation selector is not necessary and must not be used, because iOS 5 would display it as a box.
In Swift it would be
myLabel.text = "⬇\u{FE0E}"
Unicode characters being drawn differently in iOS5
You need to set the font appropriately. The blue icon you're seeing is U+25C0 in the Apple Color Emoji font. I'm not sure what other fonts on iOS include the symbol you want, but if you find that font and set it explicitly then it should render the icon you want.
Why is my attributed string being displayed oddly?
There are two different issues, as far as I can see:
- The button labels are truncated, so what you see as "3 random other characters" is the ellipsis (...). You have to enlarge the button or use a smaller font size. Perhaps also set the "Line Break" mode of the buttons to "Clip" instead of "Truncate ...".
On iOS 6 some characters (such as the "◼" symbol) are displayed as "Apple Color Emoji".
This is a (controversially discussed) "feature", see e.g. https://devforums.apple.com/message/487463#487463 (requires Apple Developer login).
As a consequence, attributes like color are ignored.The replacement by Emoji characters can be suppressed (from UILabel, UIFont and UTF-8 Triangle) by appending
the Unicode "Variation selector" U+FE0E:+ (NSArray *)validSymbols {
return @[@"◼\uFE0E",@"●",@"▲"];
}With that change, all your symbols are correctly displayed as intended.
How to display superscript asterisk in UIlabel
As per http://unicode.org/mail-arch/unicode-ml/Archives-Old/UML017/0066.html, there's no such thing as a "Superscript Asterisk" character in Unicode.
Where can I get the magnifying glass icon used in UISearchBar?
So, here's the code with the unicode character:
UILabel *magnifyingGlass = [[UILabel alloc] init];
[magnifyingGlass setText:[[NSString alloc] initWithUTF8String:"\xF0\x9F\x94\x8D"]];
[magnifyingGlass sizeToFit];
[textField setLeftView:magnifyingGlass];
[textField setLeftViewMode:UITextFieldViewModeAlways];
Edit: For plain look that fits iOS 7 style, add Unicode variation selector \U000025B6
.
How do I get a cubed symbol in a text box?
If you only need ³
, you can use the appropriate unicode character (Unicode: U+00B3, UTF-8: C2 B3). On the Mac you can use the "Character Viewer" (e.g. on "Edit" menu - "Special characters"), enter "3" in the search box, and then grab the appropriate "Related character". See the Apple help document entering unicode characters for more information.
If you need a more general use of subscripts (or you need more fine grained control over how the superscript is rendered), you can use attributed strings. Thus, the following will render something like "1,000 m3":
UIFont *font = [UIFont fontWithName:self.label.font.familyName size:self.label.font.pointSize * 0.75];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"1,000 m3"];
NSDictionary *attributes = @{(id)kCTSuperscriptAttributeName : @(1),
(id)NSFontAttributeName : font};
[string addAttributes:attributes range:NSMakeRange(7, 1)];
Related Topics
How to Overlay a Skscene Over a Scnscene in Swift
Carthage Build Failed Xcode 12 12A7209 Building
Canopenurl Not Working in iOS 10
Convert Arabic String to English Number in Swift
How to Add External Webvtt Subtitles into Http Live Stream on iOS Client
Nsuserdefaults Synchronize Not Saving On
Game Engine Collison Bitmask... Why 0X01 etc
How to Properly Send an Image to Cloudkit as Ckasset
How to Implement Gmuclusterrenderer in Swift
Missing iOS Development Signing Identity for (Null)
Memory Leak with "Libbacktracerecording.Dylib" in React Native iOS Application
How to Change Device Orientation Programmatically in Swift
Adding Views. Storyboard VS. Programmatically
Urlsessiondelegate Function Not Being Called
How to Load Multiple Storyboard Files Depending on iOS Version? (5 and 6)