/*
** lineFrame:? ? 虛線的 frame
** length:? ? ? ? 虛線中短線的寬度
** spacing:? ? ? 虛線中短線之間的間距
** color:? ? ? ? 虛線中短線的顏色
*/+ (UIView*)createDashedLineWithFrame:(CGRect)lineFrame
lineLength:(int)length
lineSpacing:(int)spacing
lineColor:(UIColor*)color{UIView*dashedLine = [[UIViewalloc] initWithFrame:lineFrame];
dashedLine.backgroundColor = [UIColorclearColor];CAShapeLayer*shapeLayer = [CAShapeLayerlayer];
[shapeLayer setBounds:dashedLine.bounds];
[shapeLayer setPosition:CGPointMake(CGRectGetWidth(dashedLine.frame) /2,CGRectGetHeight(dashedLine.frame))];
[shapeLayer setFillColor:[UIColorclearColor].CGColor];
[shapeLayer setStrokeColor:color.CGColor];
[shapeLayer setLineWidth:CGRectGetHeight(dashedLine.frame)];
[shapeLayer setLineJoin:kCALineJoinRound];
[shapeLayer setLineDashPattern:[NSArrayarrayWithObjects:[NSNumbernumberWithInt:length], [NSNumbernumberWithInt:spacing],nil]];CGMutablePathRefpath =CGPathCreateMutable();CGPathMoveToPoint(path,NULL,0,0);CGPathAddLineToPoint(path,NULL,CGRectGetWidth(dashedLine.frame),0);
[shapeLayer setPath:path];CGPathRelease(path);
[dashedLine.layer addSublayer:shapeLayer];returndashedLine;
}