kle*_*vre 2 cocoa objective-c subview nsview drawrect
我试图在我的顶部绘制NSView有一些子视图.实际上我正在尝试重现Interface Builder的连接线样式.这是我目前使用的代码:
- (void)drawRect:(CGRect)dirtyRect
{
// Background color
[[NSColor whiteColor] setFill];
NSRectFill(dirtyRect);
// Draw line
if(_connecting)
{
CGContextRef c = [[NSGraphicsContext currentContext] graphicsPort];
[[NSColor redColor] setStroke];
CGContextMoveToPoint(c, _start.x, _start.y);
CGContextAddLineToPoint(c, _end.x, _end.y);
CGContextSetLineWidth(c, LINE_WIDTH);
CGContextClosePath(c);
CGContextStrokePath(c);
}
}
Run Code Online (Sandbox Code Playgroud)
第一部分是给我上色NSView(如果你知道另一种方式,请告诉我'因为我来自iPhone开发,我想念backgroundColor属性UIView)
然后,如果检测到连接,我用2 NSPoint秒绘制它.这段代码有效,但我没有得到它来绘制子视图,只在第一个NSView.