我在VStack中有两个导航按钮,我需要帮助将点击区域限制在形状上。目前,我可以在白色空间中稍微点击形状外部,而光标根本没有接触到形状。
import SwiftUI
struct ContentView: View {
@State var showSecondView: Bool = false
@State var showThirdView: Bool = false
var body: some View {
ZStack {
// PLAY BUTTON
VStack(spacing: 20) {
NavigationStack {
Button() {
showSecondView.toggle()
}
label: {
Text("Play")
.font(.custom("Helvetica Neue", size: 25))
.bold()
.buttonBorderShape(.capsule)
.padding(.horizontal, 40)
.padding(.vertical, 10)
.background(.pink)
.foregroundColor(.white)
.cornerRadius(25)
}
.navigationDestination(
isPresented: $showSecondView) {
SecondView()
}
Spacer().frame(height: 25) //space between buttons
// HOW TO PLAY BUTTON
Button() {
showThirdView.toggle()
}
label: {
Text("How To Play")
.font(.custom("Helvetica Neue", size: 25))
.bold()
.buttonBorderShape(.capsule)
.padding(.horizontal, 20)
.padding(.vertical, 10)
.foregroundColor(.white)
.background(.pink)
.cornerRadius(25)
}
.navigationDestination(
isPresented: $showThirdView) {
ThirdView()
}
}
}
}
}
}
字符串
我不知道我需要添加或删除什么来解决这个问题。
1条答案
按热度按时间jm2pwxwz1#
您可以使用
.contentShape(Rectangle())
将点击区域限制为按钮的形状字符串