First, obtain the context
Cgcontextref context =
Uigraphicsgetcurrentcontext ();
Draw a frameless rectangle
- // Set the fill color of the rectangle to red.
- Cgcontextsetrgbfillcolor (context, 1.0, 0.0, 0.0, 1.0 );
- // Fill the rectangle
- Cgcontextfillrect (context, rect );
- // Execute painting
- Cgcontextstrokepath (context );
Framed rectangle
- // Set the fill color of the rectangle to red.
- Cgcontextsetrgbfillcolor (context, 1.0, 0.0, 0.0, 1.0 );
- // Fill the rectangle
- Cgcontextfillrect (context, rect );
- // Set the paint brush color to black.
- Cgcontextsetrgbstrokecolor (context, 0, 0, 0, 1 );
- // Set the paint brush line width
- Cgcontextsetlinewidth (context, 1.0 );
- // Draw a rectangular border
- Cgcontextaddrect (context, rect );
- // Execute painting
- Cgcontextstrokepath (context );
Draw text
- // Set the paint brush line width
- Cgcontextsetlinewidth (context, 1.0 );
- // Set the fill color of the rectangle to red.
- Cgcontextsetrgbfillcolor (context, 1.0, 0.0, 0.0, 1.0 );
- // Set the font
- Uifont * font = [uifont boldsystemfontofsize: 31.0];
- // Draw text in the specified rectangle
- [Text drawinrect: rect withfont: font];
Draw line
- // Set the paint brush line width
- Cgcontextsetlinewidth (context, 5.0 );
- // Set the line style
- Cgcontextsetlinecap (context, kcglinecapbutt );
- // Set the paint brush color to black.
- Cgcontextsetrgbstrokecolor (context, 1, 0, 0, 1 );
- // Draw point line
- Cgcontextaddlines (context, points, count );
- // Execute painting
- Cgcontextstrokepath (context );