iOS虚线

网上找的

CAShapeLayer *dotteShapeLayer = [CAShapeLayer layer];

CGMutablePathRef dotteShapePath =  CGPathCreateMutable();

//设置虚线颜色为blackColor
[dotteShapeLayer setStrokeColor:[[UIColor orangeColor] CGColor]];

//设置虚线宽度
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];

你可能感兴趣的:(iOS虚线)