【发布时间】:2011-10-27 04:07:17
【问题描述】:
我用下面的代码画了一条虚线
// get the current CGContextRef for the view
CGContextRef currentContext =
(CGContextRef)[[NSGraphicsContext currentContext]
graphicsPort];
// grab some useful view size numbers
NSRect bounds = [self bounds];
float width = NSWidth( bounds );
float height = NSHeight( bounds );
float originX = NSMinX( bounds );
float originY = NSMinY( bounds );
float maxX = NSMaxX( bounds );
float maxY = NSMaxY( bounds );
float middleX = NSMidX( bounds );
float middleY = NSMidY( bounds );
CGContextSetLineWidth( currentContext, 10.0 );
float dashPhase = 0.0;
float dashLengths[] = { 20, 30, 40, 30, 20, 10 };
CGContextSetLineDash( currentContext,
dashPhase, dashLengths,
sizeof( dashLengths ) / sizeof( float ) );
CGContextMoveToPoint( currentContext,
originX + 10, middleY );
CGContextAddLineToPoint( currentContext,
maxX - 10, middleY );
CGContextStrokePath( currentContext );
它是静态的。
但我更喜欢让破折号和间隙可移动
从右向左移动并转圈
有可能吗?
更多改进案例:
破折号和间隙自动顺时针移动
欢迎评论
【问题讨论】:
-
很棒的问题。我希望迟早要在我的代码中实现的东西只是不知道如何。 +1
标签: macos cocoa core-graphics cgcontext