Simple usage of drawing lines using DrawRect

Source: Internet
Author: User

Some simple applications for animations. Here is an example of drawing a straight line.

The method of drawing is in DrawRect

Executed, the DrawRect method is similar to Cellforrowatindexpath, and can be executed directly by the system without calling in initWithFrame or Viewdidload.

Below, draw an irregular line, the necessary code

1-(void) DrawRect: (cgrect) rect{2Self.backgroundcolor =[Uicolor Lightgraycolor];3     //Gets the context of the processing4Cgcontextref context =Uigraphicsgetcurrentcontext ();5     //set the color of a line6 Cgcontextsetstrokecolorwithcolor (context, [Uicolor Redcolor]. Cgcolor);7     //The starting point is set to (0,0): Note that this is the relative coordinate in the corresponding area of the context,8Cgcontextmovetopoint (Context,0,0);9     //set the next coordinate pointTenCgcontextaddlinetopoint (Context, -, -); One     //set the next coordinate point ACgcontextaddlinetopoint (Context,0, Max); -     //set the next coordinate point -Cgcontextaddlinetopoint (Context, -, the); the     //set the next coordinate point -Cgcontextaddlinetopoint (Context,Ten, -); -     //connect the coordinate points defined above, that is, start drawing - Cgcontextstrokepath (context); +}

The following code is non-essential. The color settings for a line can also be considered unnecessary

// Set Line Style Cgcontextsetlinecap (context, kcglinecapsquare); // Set the line thickness width, default to 1.0 1.0 ); // start a start path Cgcontextbeginpath (context);

The effect is as follows

If you want to draw a histogram, you just need to use the cgcontextsetlinewidth to draw the line thick point on it, if the line chart also the same.

Simple usage of drawing lines using DrawRect

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.