Archive for the ‘Development’ Category

Browsing Mac/iPhone Topics on Stack Overflow

Saturday, April 4th, 2009

Stack Overflow has turned into a great resource for developers, the social aspect it brings to helping other users out has brought a lot of very smart people to the site. Often times when a Google search lands me there I’ll end up browsing around a bit because I usually learn something in the process.

Since it’s not exactly obvious how to narrow down the focus to particular development topic, I wanted to share a bookmark I use to browse recent Mac and iPhone development questions:

Stack Overflow: Mac/iPhone

This works by browsing a combination of tags and has turned out to be a great addition to my list of time killers.

Sizing a Preference Pane Dynamically

Tuesday, March 10th, 2009

If you’ve tried to develop a system preference pane on the Mac that works across both Tiger and Leopard you may have run into a small but annoying problem: although the System Preferences window is resized to the height of your view it has a fixed width and does not resize your view to fit within that width. This renders any autoresizing rules applied to your view useless, so you end up with a preference pane that is either clipped on 10.4 and earlier or too small on 10.5 and later.

The Apple examples for handling this situation recommend creating two separate views sets: one set for 10.4 and earlier and another set for 10.5 and later. Unless your layout is significantly altered between the two OS versions this has some drawbacks. You now have two sets of views to build and maintain, and if a future version of OS X alters the System Preferences window size again you’re going to need yet another set.

Luckily there is a simple solution. Although System Preferences does not resize the width of our view for us we can do this ourselves quite easily by matching the content width of the System Preferences window.


- (void)mainViewDidLoad {
    NSRect rect = [[self mainView] frame];
    NSWindow *systemPrefsWindow = [[NSApplication sharedApplication] mainWindow];
    rect.size.width = [systemPrefsWindow contentRectForFrameRect:[systemPrefsWindow frame]].size.width;
    [[self mainView] setFrame:rect];
}

We could simplify this code a bit by using the superview’s frame or the contentView of systemPrefsWindow, but contentRectForFrameRect: is used for a couple of reasons. We need to resize the view before it is first displayed, but the superview will not have valid size information until didSelect, at which point our view is already on the screen. In addition, by obtaining the content rect from the window rather than the frame of the contentView we are making no assumptions about the size of whatever contentView currently represents.

This simple change sizes our main view to the width of the System Preferences window, our autoresizing rules are now applied, and viola: a single set of views that scales to a System Preferences window of any width.

Adventures With AirTunes

Monday, April 28th, 2008

The main addition to Signal 1.1 was the ability to control AirTunes speakers, something I was very happy to finally be able to offer as it was by far the most requested feature over the life of the application. Of course, with this implemented one of the new most requested features is “show which speakers are actually active!”. This is something I’d very much like to see added myself, and the reason it’s not supported stems from the same limitation of the iTunes programming interface that caused AirTunes control to be delayed for so long.

(more…)