views:

639

answers:

4

There have been a few times where I've used unicode symbols in place of small icons in one of my Cocoa apps, either because it's easier to draw inline with text or because I didn't feel like firing up Photoshop to draw a simple arrow. I've wondered though, could there be issues with localization or fonts I might not be aware of? Are there any cases where these symbols might not match what I'm seeing on my workstation?

A: 

I wouldn't do that. not consistent with the look and feel you usually get on an iPhone or a mac...

Ali Shafai
That's not true at all. As long as I'm not going all wingdings on my app and can trust it to look the same for all users, a unicode "up arrow" is going to look the same or better as a .tiff "up arrow" I draw in Photoshop.
Marc Charbonneau
what I meant was to use text as graphics, you then need to limit yourself to alignment of textual elements, as opposed to a graphics that you can make pretty to the pixel. mac is all about user experience being flawless...
Ali Shafai
It all depends on how and why you need it. One example I'm doing is using a symbol next to a text string in a table view row. Because it's all text, sizing, alignment and highlight coloring are all done for me, and I don't have to do any work subclassing NSCell. The end result looks great, and no different than if I had tried to use images instead. If the situation called for a real icon though, than yeah, I wouldn't try to shoehorn a string in its place.
Marc Charbonneau
+8  A: 

I don't see anything really wrong with this shortcut approach, especially given Apple's concern for typographic quality. In your shoes, I would consult the Unicode Code Charts, and make sure I'm very carefully specifying a programmatic unicode character rather than relying on typing it in my editor.

Since cocoa uses unicode extensively internally, and since most API methods that don't specify encoding have been deprecated for the last couple iterations of OS X, I think you're pretty safe. As you're writing a desktop/iphone app, rather than a webapp where the deployed fonts are unknown, you should be OK from a bitmap rendering standpoint if you stick to unicode characters that can be rendered by the known default fonts that ship as part of the system.

Jarret Hardie
+4  A: 

As long as you ensure it's one of the symbols included in a standard system font and it's set in the right font, there shouldn't be anything to worry about. Apple itself uses Lucida Unicode symbols all over Aqua. The only way that could go wrong on an end user's computer is if his system was broken anyway.

Chuck
+1  A: 

No; Cocoa has strong Unicode-fu. If you do have a problem, it'll probably be your fault—most likely, converting to or from the wrong encoding. (GCC used to have problems with \u sequences in @"" literals, but I believe that's fixed now.)

On the other hand, using characters such as  on a webpage is a good way to confuse non-Mac users.

Peter Hosey
"Unicode-fu" is tshirt-worthy.
Jarret Hardie
I typically use the hex character code, so it sounds like I'm safe.
Marc Charbonneau
If you're talking about having it on a web page, it doesn't matter whether you use an entity reference or the bare character. The problem is that not all fonts show the private-use characters with the same glyph. For , Apple's system fonts use the Apple logo, some Windows fonts use the Window logo, and at least one font uses the Klingon emblem—and that's just a partial list. This is true regardless of how you include the character.
Peter Hosey
is there anyway we can make custom unicode from an image . If i have image in my local directory and try to change it to unicode so that i may use it as @"\uexxx". is that possible?
Ayaz Alavi
Ayaz Alavi: You could create a font that has the desired image as a glyph for a character in the Private Use Area, embed that font in your application, and write an attributed string that uses your custom font and the character you chose. But that would restrict the “image” to black (or any other single color) on transparent, and it'd be easier just to embed the image in an attributed string.
Peter Hosey