for (int i = 0; i < 5; i ++ ) {
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
CGRect rect = shapeLayer.frame;
rect.origin.y = 50*(i+1);
shapeLayer.frame = rect;
//設(shè)置虛線顏色
[shapeLayer setStrokeColor:[UIColor redColor].CGColor];
[shapeLayer setLineJoin:kCALineJoinRound];
//設(shè)置虛線的線寬及間距
[shapeLayer setLineDashPattern:[NSArray arrayWithObjects:@5,@2,nil]];
//創(chuàng)建虛線繪制路徑
CGMutablePathRef path = CGPathCreateMutable();
//設(shè)置虛線繪制路徑起點
CGPathMoveToPoint(path, NULL, 0, 0);
//設(shè)置虛線繪制路徑終點
CGPathAddLineToPoint(path, NULL,self.view.frame.size.width, 0);
//設(shè)置虛線繪制路徑
[shapeLayer setPath:path];
CGPathRelease(path);
[self.view .layer addSublayer:shapeLayer];
}
