Draw a dashed line

Source: Internet
Author: User

Draw a dashed line, this method can be written into the classification of UIImage, directly written as a class method call.

1-(UIImage *) Drawdashimagewithframe: (CGRect) frame andlinecolor: (Uicolor *) LineColor2 {3     //turn on the graphics context4 Uigraphicsbeginimagecontext (frame.size);5     6     //Get Context7Cgcontextref Cxtref =Uigraphicsgetcurrentcontext ();8     9     //set the thread head styleTen Cgcontextsetlinecap (Cxtref, kcglinecapround); One      A     //Draw 3 points, skip 2 points, draw 3 points, skip 3 points, draw 2 points, so repeat -     //cgfloat lengths[] = {3,2,3}; -     //6 is the length of each dashed line, and 5 is the interval between dashes theCGFloat lengths[] = {6,5}; -      -     //Set line width (extend to both sides) -Cgcontextsetlinewidth (Cxtref,1); +      -     //set line Rendering color + [LineColor Setstroke]; A      at     //draw a dashed line -     //Parameter 2: How many points to skip when drawing first -     //parameter 3: Array -     //parameter 4: array length -Cgcontextsetlinedash (Cxtref,0, lengths,2); -      in     //start Drawing line-Starting point -Cgcontextmovetopoint (Cxtref,0.0,0.0); to      +     //Harness Draw Line-end point -Cgcontextaddlinetopoint (Cxtref, [UIScreen mainscreen].bounds.size.width,0.0); the      *     //Set Strokes $ Cgcontextstrokepath (cxtref);Panax Notoginseng      -     //get a picture from the graphics context theUIImage *img =Uigraphicsgetimagefromcurrentimagecontext (); +      A     //Close the graphics context the Uigraphicsendimagecontext (); +      -     returnimg; $}

Draw a dashed line

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.