I was pleased when 10.3 included the option for NSTableViews to use alternating row colors ala iTunes, but I found it odd that they didnt allow for custom colors or the ability to make the color based on the users selected appearance choice (graphite/aqua), so my apps had to stick with using my custom class to control the row colors. But I just ran across a new method in NSColor. controlAlternatingRowBackgroundColors.
Well awesome! Thanks apple. So basically this post is a tip. I just added the code below into a category on NSColor and now when the users choice is aqua, the rows are blue, if they use graphite, the rows are gray. The table even updates when the user changes while the app is running.
Devs can easily return whatever they want, but for simplicity sake the code below just respects the users system preferences. If this has already been addressed I apologise, but to me it was a "big deal". Goodbye stupid-hackish-crappy-slow-way-too-complicated NSTableview subclass!
Code:
@implementation NSColor (BLColor)
+ (NSArray *)controlAlternatingRowBackgroundColors {
NSColor *colorForControlTint = [[NSColor colorForControlTint:[NSColor currentControlTint]] highlightWithLevel:0.80];
return [NSArray arrayWithObjects:colorForControlTint, [NSColor whiteColor], nil];
}
@end