如何使用CAShapeLayer创建圆角 [英] How to create rounded corners with CAShapeLayer
本文介绍了如何使用CAShapeLayer创建圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 CAShapeLayer
中添加圆角?在我的情况下,我需要形状图层通过 lineDashPattern
创建一个虚线边框。
Is there a way to add rounded corners to a CAShapeLayer
? In my case I needed the shape layer to create a dashed border via lineDashPattern
.
^注意虚线不是舍入
推荐答案
答案很简单。创建带圆角的贝塞尔路径。
The answer is simple. Create a bezier path with rounded corners.
self.clipsToBounds = YES;
self.layer.cornerRadius = 10.0;
self.border = [CAShapeLayer layer];
self.border.fillColor = nil;
self.border.path = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:10.0];
self.border.frame = self.bounds;
self.border.strokeColor = [UIColor purpleColor].CGColor;
self.border.lineWidth = borderWidth * 2; // double desired width as half will be clipped
self.border.lineDashPattern = @[@15];
[self.layer addSublayer:self.border];
这篇关于如何使用CAShapeLayer创建圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文