美文网首页
iOS 在view上画设虚线

iOS 在view上画设虚线

作者: 冯龙胜 | 来源:发表于2017-09-25 15:34 被阅读0次

前言:很多时候我们在做界面时,UI为了适配屏幕,防止出现拉伸效果,很多细线,不会给我们切图,而是让我们自己用代码画出来。现在我就来介绍一下如何在UIView上划出一条虚线。

//设置虚线

- (void)dottedLine

{

CAShapeLayer*shapeLayer = [CAShapeLayerlayer];

[shapeLayersetBounds:self.bounds];

[shapeLayersetPosition:self.center];

[shapeLayersetFillColor:[[UIColorclearColor]CGColor]];

//设置虚线颜色为

[shapeLayersetStrokeColor:[RGB(248,211,211)CGColor]];

// 1.0f设置虚线的宽度

[shapeLayersetLineWidth:1.0f];

[shapeLayersetLineJoin:kCALineJoinRound];

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

[shapeLayersetLineDashPattern:

[NSArrayarrayWithObjects:[NSNumbernumberWithInt:3],

[NSNumbernumberWithInt:3],nil]];

// Setup the path

CGMutablePathRefpath =CGPathCreateMutable();

// 100, 40代表的是虚线最终点坐标

CGPathMoveToPoint(path,NULL,100,40);

// Setup the path

// 100,0代表初始坐标的x,y

CGPathAddLineToPoint(path,NULL,100,0);

[shapeLayersetPath:path];

CGPathRelease(path);

[self.backView.layeraddSublayer:shapeLayer];

}

相关文章

网友评论

      本文标题:iOS 在view上画设虚线

      本文链接:https://www.haomeiwen.com/subject/bihdextx.html