iOS新手学习

iOS 画一条虚线

2016-02-17  本文已影响661人  烟影很美

CAShapeLayer *shapeLayer = [CAShapeLayer layer];

shapeLayer.position = CGPointMake(1, 2);

shapeLayer.fillColor = nil;

// 设置虚线颜色

shapeLayer.strokeColor = HEXCOLOR(0xcccccc).CGColor;

// 3.0f设置虚线的宽度

shapeLayer.lineWidth = 2.0f;

shapeLayer.lineJoin = kCALineJoinRound;

// 2=线的宽度 3=每条线的间距

shapeLayer.lineDashPattern = @[@2, @3];

CGMutablePathRef path = CGPathCreateMutable();

CGPathMoveToPoint(path, NULL, 0, 0);

CGPathAddLineToPoint(path, NULL, _allview.width,0);

shapeLayer.path = path;

CGPathRelease(path);

[_allview.layer addSublayer:shapeLayer];

参考:http://www.jianshu.com/p/265b9f6fb5f2

http://www.cocoachina.com/ios/20150417/11610.html

上一篇下一篇

猜你喜欢

热点阅读