绘制矩形,线条,椭圆,填充颜色,定点写入字符串
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
// Drawing code here.
//设置4个点
NSPoint bottom=NSMakePoint((dirtyRect.size.width/2), 0);
NSPoint top=NSMakePoint((dirtyRect.size.width/2), dirtyRect.size.height);
NSPoint left=NSMakePoint(0, (dirtyRect.size.height/2));
NSPoint right=NSMakePoint(dirtyRect.size.width, dirtyRect.size.height/2);
//设置填充颜色白色
[[NSColor whiteColor] set];
[NSBezierPath fillRect:dirtyRect];
//[[NSColor colorWithCalibratedRed:0.749 green:0.749 blue:0.749 alpha:1] set];
//NSRectFill(dirtyRect);
//绘制3条线条
[[NSColor blackColor] set];
[NSBezierPath setDefaultLineWidth:4.5];
[NSBezierPath strokeRect:dirtyRect];
[NSBezierPath strokeLineFromPoint:top toPoint:bottom];
[NSBezierPath strokeLineFromPoint:left toPoint:right];
[NSBezierPath setDefaultLineWidth:1.5];
[[NSBezierPath bezierPathWithOvalInRect:dirtyRect] stroke];
//绘制字符串
NSMutableDictionary *attribs=[NSMutableDictionary dictionary];
[attribs setObject:[NSColor redColor] forKey:NSForegroundColorAttributeName];
NSString* end=@"test";
[end drawAtPoint:NSMakePoint(dirtyRect.size.width/2, dirtyRect.size.height/2)
withAttributes:attribs];
}