Alastair’s Place

Software development, Cocoa, Objective-C, life. Stuff like that.

PDFs and NSToolbar

One of the nicest new features in OS X 10.5 (Leopard) is resolution independence. Not only does this pave the way for a zoom feature that doesn’t pixellate as you zoom in, providing a better user experience for partially sighted users, but it also means that as display panel resolutions climb, the Mac OS X UI will stay a usable size and will just start to look much nicer.

So, Apple are trying to encourage developers to make their apps resolution independent. The problem with that, of course, is that it means everything must scale nicely (even to non-integer scale factors), and bitmaps just don’t do that easily. As a result, they’re suggesting that we draw several sizes of bitmap and stick them together into a multi-resolution TIFF.

That’s one way to go, certainly, but it does multiply the effort somewhat; drawing icons is hard enough without having to draw them several times at different scales and detail levels.

Anyway, some of us would rather use vector graphics where possible. (There have been some remarks about this already from the “you should use bitmaps” camp, which was later clarified after some criticism; it isn’t my intention to go into the pros and cons here).

So, away you go, changing your icons for vector graphics (probably PDF, on Mac OS X). For me, this was all working wonderfully, until I hit a stubborn problem. One of my toolbar icons, which looks like this

Go

was being rendered with a white square behind it whenever it was disabled or highlighted; i.e. like this

Go (Disabled) with a nasty white square behind it

This, of course, looks really bad, and I couldn’t work out why it only affected some icons and not others. Anyway, if you’re struggling with the same problem, a workaround is to call -setAlpha: on your NSPDFImageRep, giving the argument YES. The result in my case is that the problem went away:

Go (Disabled)

For people inside Apple, I’ve filed a bug report: rdar://4996913.