如何在 SwiftUI 列表中使整行可触摸区域?
How can I make the whole line touchable area in SwiftUI List?
此代码仅在您触摸文本时有效。如何使整行可触摸区域?
List(viewModel.countries) ) { country in
Text(country.name)
.padding(.vertical, 12)
.onTapGesture {
self.countryName = country.name
self.countryId = country.countryId
self.presentationMode.wrappedValue.dismiss()
}
}
在这里
Text(country.name)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.contentShape(Rectangle())
.onTapGesture {
此代码仅在您触摸文本时有效。如何使整行可触摸区域?
List(viewModel.countries) ) { country in
Text(country.name)
.padding(.vertical, 12)
.onTapGesture {
self.countryName = country.name
self.countryId = country.countryId
self.presentationMode.wrappedValue.dismiss()
}
}
在这里
Text(country.name)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.contentShape(Rectangle())
.onTapGesture {