the steps for customizing UIView using path drawing are as follows1 Call the Uigraphicsgetcurrentcontext () function to get Cgcontextref 2 call Cgcontextbeginpath (cgcontextref __nullable c) function to start defining path 3 Call the following function to draw the sub-path
4 If the path is added complete, call the Cgcontextclosepath () function to close path 5 to set the related properties of the path drawing: line width, fill or path color, etc. 6 call Cgcontextstrokepath (Cgcontextref __nullable c), Cgcontexteofillpath (Cgcontextref __nullable c), Cgcontextfillpath (Cgcontextref __nullable c), CGContextDrawPath ( Cgcontextref __nullable C,
Cgpathdrawingmode mode) to populate the path or draw the path border, the last method in these methods can replace the previous methods, by specifying a different cgpathdrawingmode.
drawing pictures in memory
By extending UIView, overriding the DrawRect: Method for drawing, this method is to draw all the graphics directly on the UIView control, because the DrawRect: method is called every time the control is displayed, which means that all the graphics are redrawn each time the control is displayed. Obviously this performance is very bad, sometimes need to draw pictures in memory, so that can be exported to the phone local, can also be uploaded on the network. Unlike
drawing directly on UIView, when drawing in memory, developers need to prepare their own drawing environment, and Quartz 2D provides a very agile function: Uigraphicsbeginimagecontext (cgsize size), which is used to prepare the drawing environment, and when the drawing is complete, you can call the Uigraphicsendimagecontext () function to end the drawing and close the drawing environment.
The steps for drawing in memory are as follows1 Call the Uigraphicsbeginimagecontext (cgsize size) function to prepare the drawing environment 2 call Uigraphicsgetcurrentcontext () function get Cgcontextref 3 call the following function to draw
4 Call the Uigraphicsgetimagefromcurrentimagecontext () function to get the currently drawn picture 5 call the Uigraphicsendimagecontext () function to end the drawing and close the drawing environment
Reference article: "Crazy iOS Handout"