I would like to make toolbar with my custom shape. I have been trying all day to fill my shape with UIBlurEffect.
My shape code:
struct CRectangle: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
path.addArc(center: CGPoint(x: rect.midX, y: rect.minY), radius: 20, startAngle: .zero, endAngle: .init(degrees: 180), clockwise: true)
path.move(to: CGPoint(x: rect.midX+20, y: rect.minY))
path.addLine(to: CGPoint(x: rect.maxX, y: rect.minY))
path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY))
path.addLine(to: CGPoint(x: rect.minX, y: rect.minY))
path.addLine(to: CGPoint(x: rect.midX-20, y: rect.minY))
return path
}
It works pretty well, but it is without UIBlurEffect:
struct ContentView: View {
var body: some View {
ZStack{
CRectangle()
.fill(Color.black)
.frame(width: 300, height: 100)
}
}
}
On the forum I found the code for UIBlurEffect and i added to my program, but it works not correctly, because the upper part remains empty.
struct ContentView: View {
var body: some View {
ZStack{
CRectangle()
.stroke()
.frame(width: 300, height: 100)
.background(VisualEffectView(effect: UIBlurEffect(style: .light)))
}
}
}
struct VisualEffectView: UIViewRepresentable {
var effect: UIVisualEffect?
func makeUIView(context: UIViewRepresentableContext<Self>) -> UIVisualEffectView { UIVisualEffectView() }
func updateUIView(_ uiView: UIVisualEffectView, context: UIViewRepresentableContext<Self>) { uiView.effect = effect }
}