如何在不更改 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))
}
)
}
}
}
Run Code Online (Sandbox Code Playgroud)
对于这种特殊的情况下,您可以添加填充,以排除前缘所有边缘的label
按钮:
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
Run Code Online (Sandbox Code Playgroud)
请注意,最大可点击区域应在标题上方的矩形内:
归档时间: |
|
查看次数: |
2318 次 |
最近记录: |