作为Android开发的我,在多年跃跃欲试后,终是干上了iOS!!!
如果用词不对,请帮我指定一下!
今天在实现UI效果的过程中,google一下实现了虚线的效果,做一下笔记:
代码如下(实现了一根虚线):?
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 0)];
[path addLineToPoint:CGPointMake(0, frame.size.height)];
CAShapeLayer *_shapeLine = [CAShapeLayer layer];
_shapeLine.frame = CGRectMake(frame.size.width / 2.0, 0, 0.5f, frame.size.height);
_shapeLine.lineJoin = kCALineJoinRound;
_shapeLine.lineDashPattern = @[@(2),@(2)];
_shapeLine.fillColor = [UIColor clearColor].CGColor;
_shapeLine.strokeColor =[UIColor colorWithHex:0xF0F0F0].CGColor;
_shapeLine.path = path.CGPath;
[self.layer addSublayer:_shapeLine];
同时看看一下边的实现:
UIBezierPath *path4 = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius: 10];
CAShapeLayer *border = [CAShapeLayer layer];
border.strokeColor = [UIColor blackColor].CGColor;
border.fillColor = [UIColor clearColor].CGColor;;
border.frame = self.bounds;
border.lineWidth = 1.f;
border.lineCap = @"square";
border.lineDashPattern = @[@2, @2];
border.path= path4.CGPath;
[self.layer addSublayer:border];
UIBezierPath是路径,CAShapeLayer是Shape容器,直接绘制到view的layer上,效果如下:
和Android的shape对比一下:
Android的shape与iOS UIBezierPath&CAShapeLayer对比
shape支持:line,oval,rectangle,ring ?corners | UIBezierPath在初始化时有对应的方法 暂时没有找到对应四个角单独设置的api | size,padding | CAShapeLayer.frame | solid | CAShapeLayer.fillColor | stroke | CAShapeLayer.strokeColor | stroke.dashWidth | CAShapeLayer.lineWidth?? | 支持层级 | 支持层级 |
?
?
?
?
|