Swift 为视图背景绘制弧线
Swift draw an arc for view background
我想像这样在视图的底部画一条弧线:
背景图案是另一回事,但我认为这可以用 uibezierpath 之类的东西来完成?我没有太多经验,有什么入门要点吗?谢谢
将此自定义 class 分配给 IB 中的视图
class CurveView:UIView {
var once = true
override func layoutSubviews() {
super.layoutSubviews()
if once {
let bb = UIBezierPath()
bb.move(to: CGPoint(x: 0, y: self.frame.height))
// the offset here is 40 you can play with it to increase / decrease the curve height
bb.addQuadCurve(to: CGPoint(x: self.frame.width, y: self.frame.height), controlPoint: CGPoint(x: self.frame.width / 2 , y: self.frame.height + 40 ))
bb.close()
let l = CAShapeLayer()
l.path = bb.cgPath
l.fillColor = self.backgroundColor!.cgColor
self.layer.insertSublayer(l,at:0)
once = false
}
}
}
//
我想像这样在视图的底部画一条弧线:
背景图案是另一回事,但我认为这可以用 uibezierpath 之类的东西来完成?我没有太多经验,有什么入门要点吗?谢谢
将此自定义 class 分配给 IB 中的视图
class CurveView:UIView {
var once = true
override func layoutSubviews() {
super.layoutSubviews()
if once {
let bb = UIBezierPath()
bb.move(to: CGPoint(x: 0, y: self.frame.height))
// the offset here is 40 you can play with it to increase / decrease the curve height
bb.addQuadCurve(to: CGPoint(x: self.frame.width, y: self.frame.height), controlPoint: CGPoint(x: self.frame.width / 2 , y: self.frame.height + 40 ))
bb.close()
let l = CAShapeLayer()
l.path = bb.cgPath
l.fillColor = self.backgroundColor!.cgColor
self.layer.insertSublayer(l,at:0)
once = false
}
}
}
//