I created a form in SwiftUI. There's one place I can't make round. Can you help?
This is my code :
struct BannerShape: Shape {
func path(in rect: CGRect) -> Path {
return Path { path in
path.move(to: .zero)
path.addLine(to: CGPoint(x: 0, y: 100))
path.addLine(to: CGPoint(x: UIScreen.main.bounds.width, y: 100))
path.addLine(to: CGPoint(x: UIScreen.main.bounds.width, y: 0))
path.addLine(to: CGPoint(x: UIScreen.main.bounds.width / 2 + 48, y: 0))
path.addCurve(to: CGPoint(x: UIScreen.main.bounds.width / 2 - 48, y: 0),
control1: CGPoint(x: UIScreen.main.bounds.width / 2 + 80, y: 105),
control2: CGPoint(x: UIScreen.main.bounds.width / 2 - 80, y: 105))
path.addLine(to: .zero)
path.closeSubpath()
}
}
}
In my preview :
struct TabBarBackgroundView_Previews: PreviewProvider {
// @State static var selectedTabPreview: Int = 0
static var previews: some View {
// TabBarBackgroundView(selectedTab: $selectedTabPreview)
BannerShape()
.cornerRadius(15, corners: [.topLeft, .topRight])
.previewLayout(.sizeThatFits)
.frame(width: UIScreen.main.bounds.width, height: 100)
.padding()
}
}
The result :
And I want to round off the two corners near the circle, for the moment it forms a point.
I haven't found anything to do this.
That's what I tried :
struct MyShape : Shape {
func path(in rect: CGRect) -> Path {
return Path { path in
path.move(to: .zero)
path.addLine(to: CGPoint(x: UIScreen.main.bounds.width / 2 - 48, y: 0))
path.addArc(center: CGPoint(x: UIScreen.main.bounds.width / 2 - 48, y: 10),
radius: 10,
startAngle: .degrees(-90),
endAngle: .degrees(0),
clockwise: false)
path.addCurve(to: CGPoint(x: UIScreen.main.bounds.width / 2 + 48, y: 0),
control1: CGPoint(x: UIScreen.main.bounds.width / 2 - 80, y: 105),
control2: CGPoint(x: UIScreen.main.bounds.width / 2 + 80, y: 105))
path.addArc(center: CGPoint(x: UIScreen.main.bounds.width / 2 + 48, y: 10),
radius: 10,
startAngle: .degrees(-90),
endAngle: .degrees(-180),
clockwise: true)
path.addLine(to: CGPoint(x: UIScreen.main.bounds.width, y: 0))
path.addLine(to: CGPoint(x: UIScreen.main.bounds.width, y: 100))
path.addLine(to: CGPoint(x: 0, y: 100))
path.addLine(to: .zero)
path.closeSubpath()
}
}
}
And the result...