struct Diamond: Shape { func path(in rect: CGRect) -> Path { Path() { p in p.move(to: CGPoint(x: rect.midX, y: rect.minY)) p.addLine(to: CGPoint(x: rect.midX, y: rect.minY)) p.addLine(to: CGPoint(x: rect.maxX, y: rect.midY)) p.addLine(to: CGPoint(x: rect.midX, y: rect.maxY)) p.addLine(to: CGPoint(x: rect.minX, y: rect.midY)) p.closeSubpath() } } }
struct ZigZagView: View { @State private var rotation: Double = 0 var body: some View { ForEach(0...10, id: \.self) { idx in Diamond() .frame(height: 200) .rotationEffect(.degrees(Double(idx * 30))) } } }
struct CustomShapeView: View { @State private var scale = false @State private var rotation: Double = 0 var body: some View { ZStack { Color.white ZigZagView() .foregroundColor(.red) .overlay( Text("Sale!") .font(.system(size: 78)) .bold() .textCase(.uppercase) .foregroundColor(.white) .scaleEffect(scale ? 0.5 : 1) ) .frame(width: 400, height: 400) .scaleEffect(scale ? 0.5 : 1) .rotationEffect(.degrees(rotation)) .animation(.easeInOut.speed(0.1).repeatForever(autoreverses: true), value: scale) .onAppear { scale.toggle() rotation = -30 } } } }