2
我创建NSSegmentedCell的子类,并实现drawWithFrame如下:NSSegmentedCell子类绘制
#import "CustomSegmentedCell.h"
@implementation CustomSegmentedCell
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
int i=0, count=[self segmentCount];
NSRect segmentFrame=cellFrame;
for(i=0; i<count; i++) {
segmentFrame.size.width=[self widthForSegment:i];
[NSGraphicsContext saveGraphicsState];
// Make sure that segment drawing is not allowed to spill out into other segments
NSBezierPath* clipPath = [NSBezierPath bezierPathWithRect: segmentFrame];
[clipPath addClip];
[self drawSegment:i inFrame:segmentFrame withView:controlView];
[NSGraphicsContext restoreGraphicsState];
segmentFrame.origin.x+=segmentFrame.size.width;
}
_lastDrawRect=cellFrame;
}
@end
问题是段没有拿得出第一次启动应用程序,它变得可见,只有当我用鼠标点击上分段控件假设绘制的空白区域。请让我知道,我在这里错过了什么。
感谢,
感谢Parag的代码,要求是相当老了,但我感谢您的帮助。 – AmitSri 2013-02-15 07:29:25