Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSTableView alternating row colors

NSTableView alternating row colors
Thread Tools
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Sep 15, 2004, 03:50 PM
 
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
(Last edited by 3R1C; Sep 15, 2004 at 08:58 PM. )
3R1C
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:15 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2