7

I've always thought it was great that I could use simple iconic unicode characters in a string when I needed an arrow or a bullet or whatever. The glyphs would render in the same color as the rest of the string with a nice simple and clean icons. I could preview how they'd look by using the Mac's "Special Characters" dialog on the Edit menu in XCode.

In iOS5, these glyphs render in full color and aren't simple and clean. I believe these are Emoji icons?

I'm looking for an explanation of this change, and ideally how to force iOS5 to revert to the iOS2 - iOS4 behavior.

Here's an example: @"← left arrow, right arrow → airplane ✈";

Edit:

Apparently the NSString UIKit extensions for rendering text (drawAtPoint: / drawInRect:) don't exhibit this behavior. So perhaps it is a UILabel thing? Specifically I've noticed it inside a UISegmentControl segment button, and in a UILabel.

TomSwift
  • 39,369
  • 12
  • 121
  • 149
  • I recommend filing a bug. There are plenty of times you want the Unicode character, and this should be under app control. – David Dunham Nov 09 '11 at 00:56

1 Answers1

1

This isn't a bug, it's down to the font used. When you use a character in a string that isn't available in the chosen font, iOS automatically substitutes a glyph from another font.

The system font (Helvetica) doesn't have those characters in it, so I'm guessing that Apple have have changed the list of fallback fonts so that Emoji ranks above whatever it was using previously for the fallback for those characters.

To fix it, find a font that a) has the version of the characters you want in it, and b) is available on iPhone, and set your label to use that instead of the default system font.

Alternatively, you could just make a UILabel subclass and override the drawRect method so it uses the drawAtPoint/drawInRect methods to draw the string.

Nick Lockwood
  • 40,865
  • 11
  • 112
  • 103
  • I didn't figure it to be a bug, per se. It's definitely a behavior change to use a different "fallback" font. I've been using Hiragino Kaku Gothic ProN W6 15.0 as it seems to have all of the "old" symbols. But this is really only acceptable when I dont need to intermix text and symbols. – TomSwift Mar 20 '12 at 20:54
  • The custom UILabel seems like the easiest option. If you don't feel like rolling your own, you could try my FXLabel (https://github.com/nicklockwood/FXLabel) which uses the core graphics string drawing methods, so presumably won't have this problem. – Nick Lockwood Mar 20 '12 at 23:00
  • That looks nice, thanks. It doesn't help for buttons or other controls though :( – TomSwift Mar 21 '12 at 15:27
  • It's relatively easy to inject a custom label as a subview to a UIButton and then wrap it all up in a reusable subclass. – Nick Lockwood Mar 21 '12 at 21:58
  • For that you can use [[UIBarItem alloc] initWithCustomView:....]. If you want it to look like a regular UIBarButtonItem, a neat trick is to use a UISegmentedControl as your custom view with numberOfSegments set to 1 and control style of UISegmentedControlStyleBar. That looks identical to a regular UIBarButtonItem, but because it's a view, you can add subviews (such as FXLabel). – Nick Lockwood Mar 22 '12 at 16:18
  • Yeah, I get all that. It's just a lot of work for a dumb change. – TomSwift Mar 22 '12 at 16:55
  • I can only give you the answer that there is, not the answer that you'd like there to be ;-) – Nick Lockwood Mar 22 '12 at 17:31