ios - 如何在 SwiftUI 中增加 navigationBarItem 的可点击区域?
问题描述
我有这个代码view
struct ContentView: View {
var body: some View {
NavigationView{
List{
ForEach(0...5, id: \.self) { note in
VStack(alignment: .leading) {
Text("title")
Text("subtitle")
.font(.subheadline)
.foregroundColor(.secondary)
}
}
}
.navigationBarItems(trailing: resetButton)
.navigationBarTitle(Text("Notes"))
}
}
var resetButton: some View {
Button(action: {
print("reset")
}) {
Image(systemName: "arrow.clockwise")
}
.background(Color.yellow)
}
}
当我点击 时resetButton
,似乎只有黄色区域对触摸有反应。
如何使此按钮的可点击区域更大?(让它表现得像一个正常的UIBarButtonItem
)
解决方案
您可以更改按钮view
内部的框架:
var resetButton: some View {
Button(action: {
print("reset")
}) {
Image(systemName: "arrow.clockwise")
.frame(width: 44, height: 44) // Or any other size you like
}
.background(Color.yellow)
}
推荐阅读
- python - 访问字典本身中的字典元素
- python - 在 pyQt 中创建一个覆盖整个对话框的不可见层
- vb6 - 尝试从 C# 调试到 VB6 会产生 TYPE_E_CANTLOADLIBRARY?
- angular6 - 带时间戳的角度 6 切换按钮
- windows - dial tcp [::1]:6397: connectex: 由于目标机器主动拒绝,无法建立连接
- python-3.x - 将数字添加到列表的开头
- python - Python从文本文件中删除单词和字符
- windows - 运行独立的 Windows Powershell
- latex - Pandoc:[警告] 无法转换 TeX 数学
- python - 将数字中的月份转换为单词