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