IOS: Draw dotted lines

Source: Internet
Author: User

IOS: Draw dotted lines

// Currently, this method can only be added to the self view (if there is a view on the self view, the line may be overwritten), and the painting is a dotted line // call [self drawRect: self. frame]; // override-(void) drawRect :( CGRect) rect {CGContextRef context = histogram (); CGContextBeginPath (context); CGContextSetLineWidth (context, 1 * kScreenScale ); // CGContextSetStrokeColorWithColor (context, [UIColor colorWithHex: @ "#959595"]. CGColor); // CGFloat lengths [] = {2 * kScreenScale, 1 * kScreenScale}; // set the dotted line CGContextSetLineDash (context, 0, lengths, 2 ); // set the dotted line CGContextMoveToPoint (context, 5 * kScreenScale, 3 * kScreenScale); // start point CGContextAddLineToPoint (context, 360 * kScreenScale, 3 * kScreenScale ); // draw to the first vertex CGContextAddLineToPoint (context, 362 * kScreenScale, 5 * kScreenScale); // draw to the second vertex CGContextAddLineToPoint (context, 362 * kScreenScale, 100 * kScreenScale ); // perform the following operations (context, 360 * kScreenScale, 101 * kScreenScale); CGContextAddLineToPoint (context, 5 * kScreenScale, 101 * kScreenScale); CGContextAddLineToPoint (context, 4 * kScreenScale, 100 * kScreenScale); CGContextAddLineToPoint (context, 4 * kScreenScale, 5 * kScreenScale); CGContextAddLineToPoint (context, 5 * kScreenScale, 3 * kScreenScale); CGContextStrokePath (context ); // end CGContextClosePath (context); // end}

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.