【发布时间】:2020-07-17 07:40:28
【问题描述】:
我正在尝试开发一个背景如下所示的屏幕:
在这里,我正在尝试开发灰色弯曲背景,它也填充了屏幕的下部。我对UIBezierPath 很陌生,我试过这个:
class CurvedView: UIView {
//MARK:- Data Types
//MARK:- View Setup
override func draw(_ rect: CGRect) {
let fillColor: UIColor = .blue
let path = UIBezierPath()
let y:CGFloat = 0
print(rect.height)
print(rect.width)
path.move(to: CGPoint(x: .zero, y: 100))
path.addLine(to: CGPoint(x: 60, y: 100))
path.addCurve(to: .init(x: 100, y: 0), controlPoint1: .init(x: 125, y: 80), controlPoint2: .init(x: 50, y: 80))
path.close()
fillColor.setFill()
path.fill()
}
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = .init(hex: "#dfe1e3")
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.backgroundColor = .init(hex: "#dfe1e3")
}
}
这段代码给了我这个:
我遵循了很多教程,但我没有得到确切的理解。我知道对于这条曲线,我必须移动到(0,100),然后添加一条线,然后添加一条曲线,然后十延长线添加一条曲线,然后直线下曲线,然后直线并关闭。但是,当我开始时,你可以看到蓝线没有覆盖上部。谁能帮帮我?
【问题讨论】:
标签: ios swift core-graphics uibezierpath