用UIVIew画,拖一个UIView,然后
/**
* 通过 CAShapeLayer 方式绘制虚线
*
* param lineView: 需要绘制成虚线的view
* param lineLength: 虚线的宽度
* param lineSpacing: 虚线的间距
* param lineColor: 虚线的颜色
* param lineDirection 虚线的方向 YES 为水平方向, NO 为垂直方向
**/
- (void)drawLineOfDashByCAShapeLayer:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor lineDirection:(BOOL)isHorizonal {
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setBounds:lineView.bounds];
if (isHorizonal) {
[shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
} else{
[shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame)/2)];
}
[shapeLayer setFillColor:[UIColor clearColor].CGColor];
// 设置虚线颜色为blackColor
[shapeLayer setStrokeColor:lineColor.CGC
iOS画虚线
最新推荐文章于 2024-05-11 09:28:59 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)