Recently, the company's project had to use some chart effects, and would have wanted to find some third parties on GitHub. However, the style of the third party and the company's needs are different, the change is more troublesome. So I wrote one, and it was generalized and now shared on GitHub. A bit of their own development process.
1. As soon as the first hand, want to completely use quartz2d to draw, however quartz2d can only draw some basic graphics, and can not achieve the animation effect of the path drawing. Want to fully use Uibezierpath (Uibezierpath actually also use OC syntax to quartz2d encapsulation, use more convenient) to draw, feel overqualified, and eventually feel the use of quartz2d to draw basic lines and text description, The Uibezierpath curve draws the path animation process. Note: quartz2d is rendered using CPU, so frequent drawings (such as updating graphics in real time in the touch Move method) can lead to high CPU occupancy, increased energy consumption and performance stress.
When drawing with quartz2d, it is recommended to do it directly inside the DrawRect method, which provides a graphical drawing context that can be obtained
Cgcontextref context = Uigraphicsgetcurrentcontext ();
Move to the point
Cgcontextmovetopoint (context, start.x, START.Y);
Connect to point from current context
Cgcontextaddlinetopoint (context, end.x, END.Y);
/* Path Color */
[Color Setstroke];
/* Fill color for path closure area */
[Color Setfill];
Set the dash style for a segment
CGFloat ss[] = {0.5,2,1};
Explain the following method parameters: the first parameter is the context the second parameter represents the distance segment of the pixel starting to draw the dashed line, the third represents the dashed line of the drawing rule array, such as the above SS array, which indicates that the first paragraph is 0.5 pixels long, followed by a 2-pixel dash, followed by a 1-pixel solid line. The fourth parameter indicates that if the third argument is passed into the array, the plotted dashed line pattern is executed to the number of the first array. If passed in 2, indicates that the drawing rule is the first two elements in the array.
Cgcontextsetlinedash (context, 0, SS, 2);
Here's one thing to emphasize: Arrays in Cgcontextsetlinedash should use CGFloat (although using other types may not give an error, but may cause the program to crash), do not use a float or double type array, because in iphone5s and below, The model is a 32-bit operating system, the above 64 is the operating system, so if you use a float or double type, the iphone5s and below will cause the program to crash, as follows, the system definition of cgfloat.
#if defined (__lp64__) && __lp64__
# define Cgfloat_type Double
# define Cgfloat_is_double 1
# define Cgfloat_min dbl_min
# define Cgfloat_max Dbl_max
#else
# define Cgfloat_type Float
# define Cgfloat_is_double 0
# define Cgfloat_min flt_min
# define Cgfloat_max Flt_max
#endif
Drawing-line drawing related