【问题标题】:How can I make the whole line touchable area in SwiftUI List?如何在 SwiftUI List 中制作整行可触摸区域?
【发布时间】:2020-09-26 09:15:51
【问题描述】:

此代码仅在您触摸文本时有效。如何使整行可触摸区域?

List(viewModel.countries) ) { country in
        Text(country.name)
            .padding(.vertical, 12)
            .onTapGesture {
                self.countryName = country.name
                self.countryId = country.countryId
                self.presentationMode.wrappedValue.dismiss()
        }
    }

【问题讨论】:

    标签: list swiftui row


    【解决方案1】:

    在这里

        Text(country.name)
            .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
            .contentShape(Rectangle())         
            .onTapGesture {
    

    【讨论】:

    • 只需将Button 添加到您的列表中,它将自动将所有单元格区域贴上胶带,并具有很好的点击效果...而不是使用框架
    猜你喜欢
    • 2019-11-09
    • 1970-01-01
    • 2016-12-21
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    • 2020-09-18
    • 1970-01-01
    相关资源
    最近更新 更多