In the recent project design, there was a dashed line divider, reminiscent of a control yrborderview that was used to draw various edge effects, but only the actual lines were supported and immediately upgraded.
Supports four edges with different colors, different weights, different radians, supports clipping off edges outside, and supports dashed lines.
:
You need to try the stamp of this control: Yrborderview
For simple lines and drawing please see my previous Coregraphics Series blog:
http://blog.csdn.net/u010124617/article/details/9222753
Here again to illustrate the next dashed line drawing, using Cgcontextsetlinedash, for the equal width of the dashed line, generally:
CGFloat lengths[] = {间隔长度};
CGContextSetLineDash(context, 0, lengths,1);
You can do it.
If you need more complex drawing, you need to parse the parameters of this method:
CGContextSetLineDash(CGContextRef c, CGFloat phase,
const CGFloat lengths[], size_t count)
which
- The first parameter is the context in which the drawing is used
- The phase parameter indicates how much distance is skipped when drawing the first segment
- The lengths parameter is an array of interval distances drawn
- Count is the length of the third parameter lengths array
The more difficult to understand is lengths this parameter, in fact it is this:
Think of your dashed line, each piece of solid lines and each segment is a small line, but one part of the visible, part is not visible, then for each small line of the drawing rule is to follow the values in the lengths array to continue.
For example, lengths[] = {5,10,15};
The first paragraph length is 5---(line)
The second paragraph length is 10---(blank)
The third paragraph length is 15---(line)
Fourth paragraph length is 5---(blank)
The fifth paragraph length is 10---(line)
......
This makes up an irregular dashed line, such as
If our second parameter is set at 3, then the length of the first small segment will be 5-3=2, and then continue to be 10, 15 ... or something like that.
Hope to help everyone.
iOS development-Edge drawing controls and dashed line drawing principles