IOS uses quartz to draw rectangles, text, and lines

Source: Internet
Author: User

First, obtain the context

Cgcontextref context =
Uigraphicsgetcurrentcontext ();


Draw a frameless rectangle

  1. // Set the fill color of the rectangle to red.
  2. Cgcontextsetrgbfillcolor (context, 1.0, 0.0, 0.0, 1.0 );
  3. // Fill the rectangle
  4. Cgcontextfillrect (context, rect );
  5. // Execute painting
  6. Cgcontextstrokepath (context );

 

Framed rectangle

  1. // Set the fill color of the rectangle to red.
  2. Cgcontextsetrgbfillcolor (context, 1.0, 0.0, 0.0, 1.0 );
  3. // Fill the rectangle
  4. Cgcontextfillrect (context, rect );
  5. // Set the paint brush color to black.
  6. Cgcontextsetrgbstrokecolor (context, 0, 0, 0, 1 );
  7. // Set the paint brush line width
  8. Cgcontextsetlinewidth (context, 1.0 );
  9. // Draw a rectangular border
  10. Cgcontextaddrect (context, rect );
  11. // Execute painting
  12. Cgcontextstrokepath (context );

 

Draw text

  1. // Set the paint brush line width
  2. Cgcontextsetlinewidth (context, 1.0 );
  3. // Set the fill color of the rectangle to red.
  4. Cgcontextsetrgbfillcolor (context, 1.0, 0.0, 0.0, 1.0 );
  5. // Set the font
  6. Uifont * font = [uifont boldsystemfontofsize: 31.0];
  7. // Draw text in the specified rectangle
  8. [Text drawinrect: rect withfont: font];

 

Draw line

  1. // Set the paint brush line width
  2. Cgcontextsetlinewidth (context, 5.0 );
  3. // Set the line style
  4. Cgcontextsetlinecap (context, kcglinecapbutt );
  5. // Set the paint brush color to black.
  6. Cgcontextsetrgbstrokecolor (context, 1, 0, 0, 1 );
  7. // Draw point line
  8. Cgcontextaddlines (context, points, count );
  9. // Execute painting
  10. Cgcontextstrokepath (context );

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.