【发布时间】:2017-09-12 09:14:23
【问题描述】:
我有一个设计元素我无法弄清楚;希望有人能指出我正确的方向。我正在尝试构建的元素是这样的;
实际上,它是一个圆角矩形,在左侧、顶部和右侧都有一个笔划(底部应该没有笔划)。
我已经尝试过使用以下代码;
// Create the rounded rectangle
let maskPath = UIBezierPath(roundedRect: myView.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 4.0, height: 4.0))
// Setup a shape layer
let shape = CAShapeLayer()
// Create the shape path
shape.path = maskPath.cgPath
// Apply the mask
myView.layer.mask = shape
随后,我使用以下内容在矩形周围绘制笔划;
// Add border
let borderLayer = CAShapeLayer()
borderLayer.path = maskPath.cgPath
borderLayer.fillColor = UIColor.clear.cgColor
borderLayer.strokeColor = UIColor.white.cgColor
borderLayer.lineWidth = 2.0
borderLayer.frame = self.bounds
self.layer.addSublayer(borderLayer)
这会产生以下图像;
我无法弄清楚如何删除底部笔划或使用 UIBezierPath() 绘制项目,但以某种方式圆角这将与圆角矩形相同(我在同一视图中使用另一个圆角矩形用于不同的目的,圆角需要相同)。
谢谢!
【问题讨论】:
标签: ios swift calayer uibezierpath