first, get context cgcontextref contexts=uigraphicsgetcurrentcontext (); Copy Code draw line//Set Brush line weightCgcontextsetlinewidth (Context,5.0); //Set Line StyleCgcontextsetlinecap (context, Kcglinecapbutt); //Set Brush color: BlackCgcontextsetrgbstrokecolor (Context,1,0,0,1); //draw some lines.Cgcontextaddlines (context, points, count); //Perform paintingCgcontextstrokepath (context); Copy code draw a rectangle without a frame//Set Rectangle fill color: RedCgcontextsetrgbfillcolor (Context,1.0,0.0,0.0,1.0); //Fill Rectanglecgcontextfillrect (context, rect); //Perform paintingCgcontextstrokepath (context); Copy code draw a box rectangle//Set Rectangle fill color: RedCgcontextsetrgbfillcolor (Context,1.0,0.0,0.0,1.0); //Fill Rectanglecgcontextfillrect (context, rect); //Set Brush color: BlackCgcontextsetrgbstrokecolor (Context,0,0,0,1); //Set Brush line weightCgcontextsetlinewidth (Context,1.0); //draw a rectangular borderCgcontextaddrect (Context,rect); //Perform paintingCgcontextstrokepath (context); Copy code to draw text//Set Brush line weightCgcontextsetlinewidth (Context,1.0); //Set Rectangle fill color: RedCgcontextsetrgbfillcolor (Context,1.0,0.0,0.0,1.0); //Set FontUifont *font = [Uifont boldsystemfontofsize:31.0]; //Draw text inside a specified rectangular area[text Drawinrect:rect withfont:font]; Copy Code
How IOS draws lines, rectangles, and text