SwiftUI:如何让Section内的Button整行可点击而非仅文本
问题:List的Section中Log Out按钮仅文本区域可点击,需实现整行可点击
我尝试在带Section的List中添加一个Log Out按钮,但目前只有“Log Out”文本区域可点击,而非整行Section区域。我不想让按钮尺寸超出当前Section范围。
我曾在线搜索类似问题,但找到的案例均涉及在一个Section内设置两个可点击元素,而非让整行可点击。
相关代码如下:
Section{ //Log out button Button("Log Out"){ signOutAlert = true } .foregroundColor(.red) .buttonStyle(.borderless) .alert(isPresented: $signOutAlert){ Alert( title: Text("Log Out"), message: Text("Are you sure you want to log out?"), primaryButton: .destructive(Text("Log Out")){ do { try Auth.auth().signOut() auth_status.current_status = .unauthenticated } catch let signOutError as NSError { print("Error logging out") } }, secondaryButton: .cancel() ) } }
与Navigation或Link不同,该按钮无法整行点击。是否有其他方式保留我的登出功能?
编辑补充:
正如@flanker指出,问题出在.buttonStyle(.borderless),移除该样式即可实现预期效果。
内容的提问来源于stack exchange,提问作者thatsquitemid
相关产品推荐
相关产品推荐

