其中的一个方法
/**
*画虚线
@param lineView 视图
@param lineLength 单个虚线大小
@param lineSpacing 间隔
@param lineColor 虚线颜色
*/
+(void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor{
CGRect rect = CGRectMake(0, 0, CGRectGetWidth(lineView.frame), CGRectGetHeight(lineView.frame));
CGSize radii = CGSizeMake(5, 5);//圆角
UIRectCorner corners = UIRectCornerAllCorners;
//create path
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:radii];
//create shape layer
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.strokeColor = lineColor.CGColor;
shapeLayer.fillColor = [UIColor clearColor].CGColor;
shapeLayer.lineWidth = 0.5;//line的高度
shapeLayer.lineJoin = kCALineJoinRound;
shapeLayer.lineCap = kCALineCapRound;
shapeLayer.path = path.CGPath;
shapeLayer.lineDashPattern = @[[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing]];//画虚线(虚线宽、虚线间隔)
//add it to our view
[lineView.layer addSublayer:shapeLayer];
}
网友评论