gpt4 book ai didi

ios - SwiftUI:如何增加可以触发按钮的区域?

转载 作者:行者123 更新时间:2023-12-01 21:19:28 31 4
gpt4 key购买 nike

如何在不更改 UI 的情况下增加可以触发按钮的区域?

这是我的代码

struct ContentView: View {
var body: some View {
NavigationView {
Text("Text")

.navigationBarTitle(Text("Title"))
.navigationBarItems(
leading:
Button(action: { print("add") }) {
Image(systemName: SFSymbolName.plus)
.font(.system(size: 18))
}
)
}
}
}

最佳答案

对于这种特殊情况,您可以向除前缘之外的所有边缘添加填充到按钮的标签:

Button(action: { print("add") }) {
Text("+")
.padding(EdgeInsets(top: 20, leading: 0, bottom: 20, trailing: 50))
}
.background(Color.red) // This is just for seeing the hit area. You should get rid of it

请注意最大可点击区域应位于标题上方的矩形内:

enter image description here

关于ios - SwiftUI:如何增加可以触发按钮的区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58675768/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com