如何在swift中剪切UIView的一些边缘?

问题描述 投票:0回答:1

enter image description here

我尝试在互联网上进行研究,但没有任何资源可以在 Swift UIKit/SwiftUI 中绘制或剪切 UIView 的一些边缘。如果有人知道或者可以像上图那样做,我真的很感激。我非常需要你的帮助。谢谢你们!

swift swiftui uikit
1个回答
0
投票

结构ContentView:视图{

var body: some View {
    VStack {
        ZStack {
            Color.red
            VStack(alignment: .leading) {
                Text("$0.0")
                    .padding(.top, 10)
                    .padding(.horizontal)
                Image("ic_test")
                    .resizable()
                    .scaledToFill()
            }
            // 👉 You can modify the frame, rotation, and offset of the overlay according to your requirements.
            .overlay(alignment: .topTrailing) {
                Rectangle()
                    .fill(.red)
                    .frame(width: 150, height: 40) // 👈
                    .rotationEffect(.degrees(35)) // 👈
                    .offset(x: 80, y: -15)  // 👈
                    .clipped()
            }
            .background(.white)
            .padding(.top, 50)
        }
    }
    .cornerRadius(16)
    .frame(width: 300, height: 300)
    .shadow(color: Color.gray, radius: 10, x: 0, y: 0)
}
}

您可以修改叠加层的框架、旋转和偏移 根据您的要求。

© www.soinside.com 2019 - 2024. All rights reserved.