項(xiàng)目中用到了自己畫(huà)的虛線袍祖,記錄一下:
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
// 畫(huà)虛線
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setFillColor:[[UIColor clearColor] CGColor]];
// 設(shè)置虛線顏色為blackColor
[shapeLayer setStrokeColor:[[UIColor colorWithHex:@"#dcd2de"] CGColor]];
[shapeLayer setStrokeColor:[[UIColor colorWithRed:223/255.0 green:223/255.0 blue:223/255.0 alpha:1.0f] CGColor]];
// 3.0f設(shè)置虛線的寬度
[shapeLayer setLineWidth:1.0f];
[shapeLayer setLineJoin:kCALineJoinRound];
// 8=線的寬度 3=每條線的間距
[shapeLayer setLineDashPattern:
[NSArray arrayWithObjects:[NSNumber numberWithInt:8],
[NSNumber numberWithInt:6],nil]];
// Setup the path
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 25, 15);
CGPathAddLineToPoint(path, NULL, frame.size.width-25,15);
[shapeLayer setPath:path];
CGPathRelease(path);
// 可以把self改成任何你想要的UIView
[[self layer] addSublayer:shapeLayer];
}
return self;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者