【发布时间】:2013-08-27 12:01:19
【问题描述】:
我喜欢继承一个 NSProgressIndicator。我已经使用了这段代码,并在 Interface Builder 中设置了子类:
- (void)drawRect:(NSRect)dirtyRect {
NSRect rect = NSInsetRect([self bounds], 1.0, 1.0);
CGFloat radius = rect.size.height / 2;
NSBezierPath *bz = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius];
[bz setLineWidth:2.0];
[[NSColor blackColor] set];
[bz stroke];
rect = NSInsetRect(rect, 2.0, 2.0);
radius = rect.size.height / 2;
bz = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius];
[bz setLineWidth:1.0];
[bz addClip];
rect.size.width = floor(rect.size.width * ([self doubleValue] / [self maxValue]));
NSRectFill(rect);
当应用程序启动时,它的外观如下:
但是在复制过程中,旧条出现了。
怎么了?
【问题讨论】:
-
你忘了添加 [super drawRect:rect]
-
它不适用于 [super drawRect:rect]。
-
所以我将 NSLog 添加到我的子类中,并且子类在开始时只调用一次,但在复制过程中从不调用该类。
标签: macos cocoa subclass nsprogressindicator