I'm trying to draw at the top of my NSView
which has some subviews. In fact I'm trying to reproduce the connection line style of Interface Builder. Here is the code I'm using for the moment:
- (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);
}
}
The first part is to color my NSView
(if you know an other way, tell me please 'cause I come from iPhone development and I miss the backgroundColor
property of UIView
)
Then if a connection if detected, I draw it with 2 NSPoint
s. This code works but I didn't get it to draw over subviews, only on the first NSView
.
A parent view cannot draw over its subviews. You would have to place another view over the subviews and draw the line there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.