admin管理员组文章数量:1435859
In a grid View, here a LazyVGrid
, I understand that to make a row "tappable" one should add the .contentShape()
modifier with a Rectangle()
shape:
LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) {
Text("first column")
Text("second column")
// potentially many columns
}
//.overlay(content: { Rectangle().fill() })
.contentShape(Rectangle())
.onTapGesture {
print("row tapped")
}
However, while the space in the row is now tappable, clicking on the text is not recognized as a tap. The text is selectable for copying because I have .textSelection(.enabled)
on its container.
Is there a way to make the text tappable as well?
And can that be achieved while allowing it to still be selectable?
- I have found that using an
overlay
with a filled Rectangle works, but not if thefill
isColor.clear
. - I saw an idea to
fill
with UIColor of System background, but I would rather not import UIKit. - I saw the idea of using a fill with
opacity
so little that it was not apparent to the user. Is that really the only way to do it? (Also the text is no longer selectable.)
本文标签: SwiftUIMake Grid row selectable including the textStack Overflow
版权声明:本文标题:SwiftUI - Make Grid row selectable including the text? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745673741a2669725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论