我的自定义NSView与我的xib中的自定义视图相关联。
代码:
@implementation GDStatusPopoverActivateButton
- (void)drawRect:(NSRect)dirtyRect {
NSBezierPath* path = [GDAssets getPathForTimesIconWithRect: self.bounds];
NSAffineTransform* transformer = [[NSAffineTransform alloc] init];
[transformer scaleBy: 0.25];
[path transformUsingAffineTransform: transformer];
[[NSColor blackColor] setFill];
[path fill];
[super drawRect: dirtyRect];
}
@end
路径代码(GDAssets getPathForTimesIconWithRect调用)。
+ (NSBezierPath *) getPathForTimesIconWithRect: (NSRect) rect {
NSBezierPath* timesPath = [NSBezierPath bezierPathWithRect: rect];
[timesPath moveToPoint: NSMakePoint(128, 240.48)];
[timesPath curveToPoint: NSMakePoint(15.52, 128) controlPoint1: NSMakePoint(65.88, 240.48) controlPoint2: NSMakePoint(15.52, 190.12)];
[timesPath curveToPoint: NSMakePoint(128, 15.51) controlPoint1: NSMakePoint(15.52, 65.88) controlPoint2: NSMakePoint(65.88, 15.51)];
[timesPath curveToPoint: NSMakePoint(240.48, 128) controlPoint1: NSMakePoint(190.12, 15.51) controlPoint2: NSMakePoint(240.48, 65.88)];
[timesPath curveToPoint: NSMakePoint(128, 240.48) controlPoint1: NSMakePoint(240.48, 190.12) controlPoint2: NSMakePoint(190.12, 240.48)];
[timesPath closePath];
[timesPath moveToPoint: NSMakePoint(256, 128)];
[timesPath curveToPoint: NSMakePoint(128, 0) controlPoint1: NSMakePoint(256, 57.31) controlPoint2: NSMakePoint(198.69, 0)];
[timesPath curveToPoint: NSMakePoint(0, 128) controlPoint1: NSMakePoint(57.31, 0) controlPoint2: NSMakePoint(0, 57.31)];
[timesPath curveToPoint: NSMakePoint(128, 256) controlPoint1: NSMakePoint(0, 198.69) controlPoint2: NSMakePoint(57.31, 256)];
[timesPath curveToPoint: NSMakePoint(256, 128) controlPoint1: NSMakePoint(198.69, 256) controlPoint2: NSMakePoint(256, 198.69)];
[timesPath closePath];
return timesPath;
}
XIB:
结果:
答案 0 :(得分:0)
这条线是罪魁祸首
NSBezierPath* timesPath = [NSBezierPath bezierPathWithRect: rect];
溶液:
NSBezierPath* timesPath = [NSBezierPath bezierPath];