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}