網(wǎng)上找的
CAShapeLayer *dotteShapeLayer = [CAShapeLayer layer];
CGMutablePathRef dotteShapePath = CGPathCreateMutable();
//設(shè)置虛線顏色為blackColor
[dotteShapeLayer setStrokeColor:[[UIColor orangeColor] CGColor]];
//設(shè)置虛線寬度
dotteShapeLayer.lineWidth = 1.0f ;
//10=線的寬度 5=每條線的間距
NSArray *dotteShapeArr = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:3], nil];
[dotteShapeLayer setLineDashPattern:dotteShapeArr];
// 50為虛線Y值亏吝,和下面的50一起用压固。
// kScreenWidth為虛線寬度
CGPathMoveToPoint(dotteShapePath, NULL, 0 ,50);
CGPathAddLineToPoint(dotteShapePath, NULL, kScreenWidth, 50);
[dotteShapeLayer setPath:dotteShapePath];
CGPathRelease(dotteShapePath);
//把繪制好的虛線添加上來
[self.layer addSublayer:dotteShapeLayer];