Sat, 10 Sep 2005

The initial reaction to the new window style in iTunes 5 seems to be mixed. However, just about everyone universally condemns it for introducing yet another style into an already inconsistent user interface. Personally, I think the sooner brushed metal is gone, the better. And so to further that cause, I present the secret to making your very own Polished Metal windows.

Step 1 - Pre-conditions

We start off with a standard Brushed Metal window. Using any other base window style for what we are going to do won't work.

Step 2 - Margins and Layout

Next, we divide the content of the window into 3 basic areas: Header, Body, and Footer.

Our header is comprised of the window title bar, and any number of pixels below it.

The body is everything below that and above the footer, and can not reveal any of the window background (you'll see why in step 3). Some single pixel black border lines are also recommended.

Finally the footer is any size of space below the body.

Step 3 - Header gradient

Now then, we are ready to install our first bit of polished metal, the gradient that will be displayed in the header.

First thing we do is compute the height of the header. In our example window, our header area is 38 pixels tall, plus the height of the title bar. The title bar of a Brushed Metal window is 22 pixels, so the total height we need is 60 pixels.

So we fire up Photoshop, and make the approriate gradient by just using the Gradient tool, and sucking color values out of iTunes with the Apple Color Picker:

Now for the real magic. To get our window to display our header gradient, we set the window's background color. Makes sense, right? Not to me either, but that's how it works. First we create an NSColor based off our gradient image, and then setBackgroundColor: on the window itself:

That will give us this:

So now our header is looking good, but you'll note that the footer doesn't look quite right. What's happening is, NSWindow tiles it's background image. So our 60 pixel high header gradient repeats itself over and over again. This is precisely why the body section can not show any of the window background. So next, we fix the footer.

Step 4 - Footer gradient

To fix the footer, we'll just draw a proper gradient over the background. So we go back to Photoshop and create a second footer gradient image of the proper height (amazingly enough in our example here, that height is 60 pixels). Then in Interface Builder we just drop in an NSImageView into the footer area, and set it to display the footer gradient:

Step 5 - Post-conditions

And that gives us the final results:

Which for thirty minutes of work isn't half bad. It's not a pixel-by-pixel clone, but it's passable. The big differences between it and iTunes 5, are the window corners and the resize thumb. The upper corners are too round, and the lower corners aren't round enough. The only way to fix that would be to reimplement the entire window from scratch with the base window being a borderless window (which is what iTunes does).

But now you know the secret: -[NSWindow setBackgroundColor:] & +[NSColor colorWithPatternImage:]. Now try not to do quite so much evil with it as Gus.

Update 1:
Mark Johns notes that if you add a little transparency to the footer image, you can round the bottom corners back out.

Update 2:
Matt Gemmell shows how to do it and avoid having the background image tile.

Posted by Quentin | Permalink | View/Post Comments (13)

Comments


Jeff Hume
Sat Sep 10 00:08:51 2005

Very nicely done. I love the look. I would suggest, however, that having the corners as you have them is not a mistake but a huge improvement. Those iTunes corners truely are awful.

Don't even try to use them, people.

Joseph Michaels
Sat Sep 10 00:43:02 2005

I agree with Jeff, at least for the top corners. The bottom, however, either has too much padding around the sizer or needs a slight curve.

Really, it should probably look like the status bar in normal Unified apps: small sizer, no margins.

Jesper
Sat Sep 10 04:27:14 2005

Gemmell's code, while otherwise excellent, does not work good at all once you resize the window. Is there a workaround?

Jesper
Sat Sep 10 06:26:14 2005

Gemmell's code, while otherwise excellent, does not work good at all once you resize the window. Is there a workaround?

Steve Kellener
Sat Sep 10 13:04:44 2005

While I don't mind the new grey look, I still prefer rounded corners.  I always have.  I wish Apple would decide on a UI and stick with it.  It's a mess right now.  Nice tutorial.

Ingrid Larsen
Sun Sep 11 11:34:34 2005

Or, you could just install Iridium:
http://macupdate.com/info.php/id/19074

It makes all of the windows on MacOS 10.4 look like the new Unified ones. it even has a skin for iTunes 5!

Paul
Sun Sep 11 13:19:59 2005

I suppose we could just tell users to install a whole theme. But how well would you react to a developer telling you that if you wanted their application to look right, they had to theme their whole system? 8)

Matt Gemmell
Mon Sep 12 05:58:58 2005

Hi all,

Just a note that I've updated my iTunes 5 window style code. The new version also draws the other gradient along the bottom of the window, fixed a memory leak, and works as expected when the window is zoomed or resized. Same download URL as before (linked from Quentin's article above).

Cheers,
-M

Eug Wanker
Mon Sep 12 06:47:02 2005

Wouldn't Mail.app qualify as the first polished metal app?

Anyways I've always loved brushed metal. I had hoped all the apps were going that direction, but I guess not. Brushed metal does look good though.

Jonas Johansson
Tue Sep 13 13:05:31 2005

Would anyone know how they make the split view separator go away?

Julian Cain
Tue Sep 13 19:43:55 2005

"Would anyone know how they make the split view separator go away?"

Just subclass NSSplitView and return 1.0; for the divider width.

Jon
Wed Sep 14 19:21:06 2005

I'm new to Cocoa and am having difficulty getting either set of examples to work.  Perhaps you could have a more full featured tutorial?  Maybe Matt would include an Xcode project with his code release?

Jon
Thu Sep 15 03:23:46 2005

Turns out I was just making simple mistakes.  Thanks for the information.


This post is archived, and commenting has been closed.