0
我创建了一个NSOutlineView的子类,并使用下面的代码使行颜色交替。NSOutlineView没有做它应该做的它的子类
头文件。
#import <Cocoa/Cocoa.h>
@interface MyOutlineView : NSOutlineView {
}
- (void) drawStripesInRect:(NSRect)clipRect;
@end
执行文件。
#import "MyOutlineView.h"
// RGB values for stripe color (light blue)
#define STRIPE_RED (237.0/255.0)
#define STRIPE_GREEN (243.0/255.0)
#define STRIPE_BLUE (254.0/255.0)
static NSColor *sStripeColor = nil;
@implementation MyOutlineView
// This is called after the table background is filled in,
// but before the cell contents are drawn.
// We override it so we can do our own light-blue row stripes a la iTunes.
- (void) highlightSelectionInClipRect:(NSRect)rect {
[self drawStripesInRect:rect];
[super highlightSelectionInClipRect:rect];
}
// This routine does the actual blue stripe drawing,
// filling in every other row of the table with a blue background
// so you can follow the rows easier with your eyes.
- (void) drawStripesInRect:(NSRect)clipRect {
NSRect stripeRect;
float fullRowHeight = [self rowHeight] + [self intercellSpacing].height;
float clipBottom = NSMaxY(clipRect);
int firstStripe = clipRect.origin.y/fullRowHeight;
if (firstStripe % 2 == 0)
firstStripe++; // we're only interested in drawing the stripes
// set up first rect
stripeRect.origin.x = clipRect.origin.x;
stripeRect.origin.y = firstStripe * fullRowHeight;
stripeRect.size.width = clipRect.size.width;
stripeRect.size.height = fullRowHeight;
// set the color
if (sStripeColor == nil)
sStripeColor = [[NSColor colorWithCalibratedRed:STRIPE_RED
green:STRIPE_GREEN
blue:STRIPE_BLUE
alpha:1.0] retain];
[sStripeColor set];
// and draw the stripes
while (stripeRect.origin.y < clipBottom) {
NSRectFill(stripeRect);
stripeRect.origin.y += fullRowHeight * 2.0;
}
}
@end
但问题是,什么样的代码是应该做的不会发生在大纲视图,代码是正确的,但我需要的大纲视图连接到的代码是某种方式?
完美!你太棒了!只是想知道如果你能帮助我最后一件事,我将如何使网格线颜色黄色而不是蓝色。我知道我将不得不改变它所说的定义的数字,但我需要改变它到什么地方?非常感谢! – Joshua 2009-06-14 19:06:49