Skip navigation.
 
mlRe: NSTableView - Alternating blue and white background
FROM : Erik J. Barzeski
DATE : Tue Dec 17 18:50:28 2002

Hi,

Stephane said:
>>> One solution is described in some Mac Tech articles written by Dan
>>> Wood. The code is available on his web site and IIRC, if you search
>>> the
>>> archive you should find a post indicating the URL of the source codes.

>>
>> Unfortunately, this method is subject to rounding errors, so if you
>> expect
>> to have a few hundred (or more) rows in the table view, eventually the
>> colors won't line up. You'll have a line that's half blue, half white,
>> etc.

>
> Interesting. With how many lines are you seeing this side effect? I'm
> using another method similar to that one so I may be affected by this
> bug too. I tested with a hundred cells or so and didn't see this.


I don't recall the specifics, but it worked out to about 500. Let me see if
I can re-enable it quickly...

Hmm, actually even around the 70th row it's clearly visible. Perhaps I
didn't re-set everything, but, here's what it looks like:

http://iacas.org/asm/misaligned.gif

>> Overriding the table cell drawing method is what we had to use in
>> MailDrop.

>
> But when the table is empty, there is no stripped background?


Correct. And your intercell spacing has to be 0, I believe, or you get
little white gaps. That's the downside, yes.

Here's the code I believe I got right from Dan Wood's tutorial. Perhaps I'd
made a typo, but this is the code used to generate the misaligned table view
colored rows above:

{
    NSColor *evenColor = [NSColor colorWithCalibratedRed:0.929 green:0.953
blue:0.996 alpha:1.0];
    NSColor *oddColor = [NSColor whiteColor];

    float rowHeight = [self rowHeight] + [self intercellSpacing].height;
    NSRect visibleRect = [self visibleRect];

    NSRect highlightRect;
    highlightRect.origin = NSMakePoint(NSMinX(visibleRect),
(int)(NSMinY(clipRect))/rowHeight);
    highlightRect.size = NSMakeSize(NSWidth(visibleRect), rowHeight - [self
intercellSpacing].height);

    while(NSMinY(highlightRect) < NSMaxY(clipRect))
    {
        NSRect clippedHighlightRect = NSIntersectionRect(highlightRect,
clipRect);
        int row = (int)((NSMinY(highlightRect)+rowHeight/2.0)/rowHeight);
        NSColor *rowColor = (0 == row % 2) ? evenColor : oddColor;
        [rowColor set];
        NSRectFill(clippedHighlightRect);
        highlightRect.origin.y += rowHeight;
    }
    [super highlightSelectionInClipRect:clipRect];
}



--
    Best wishes,
    Erik J. Barzeski

Any fool can know. The point is to understand. - Albert Einstein
###################################################################
Email: erik@(anything below)        AIM: iacas

                    <A href="http://weims.net">http://weims.net
                  <A href="http://barzeski.com">http://barzeski.com
          <A href="http://soundsetcentral.com">http://soundsetcentral.com
  <A href="http://applescriptcentral.com">http://applescriptcentral.com
###################################################################
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlNSTableView - Alternating blue and white background Flemming Bengtsson Dec 17, 10:53
mlRe: NSTableView - Alternating blue and white background David Remahl Dec 17, 11:03
mlRe: NSTableView - Alternating blue and white background Warren.Burton Dec 17, 11:03
mlRe: NSTableView - Alternating blue and white background Cristi Savu Dec 17, 11:05
mlRe: NSTableView - Alternating blue and white background j o a r Dec 17, 11:15
mlRe: NSTableView - Alternating blue and white background j o a r Dec 17, 11:38
mlRe: NSTableView - Alternating blue and white background Stéphane Sudre Dec 17, 11:38
mlRe: NSTableView - Alternating blue and white background Erik J. Barzeski Dec 17, 16:04
mlRe: NSTableView - Alternating blue and white background Joe Lester Dec 17, 17:15
mlRe: NSTableView - Alternating blue and white background Stéphane Sudre Dec 17, 17:19
mlRe: NSTableView - Alternating blue and white background Erik J. Barzeski Dec 17, 18:50
mlRe: NSTableView - Alternating blue and white background Joe Lester Dec 17, 20:31
mlRe: NSTableView - Alternating blue and white background Erik J. Barzeski Dec 17, 20:51
mlRe: NSTableView - Alternating blue and white background John C. Randolph Dec 17, 20:53