Quantcast
Channel: Active questions tagged strikethrough - Stack Overflow
Viewing all articles
Browse latest Browse all 88

How to apply strikethrough() to a tapped foreach Text item in SwiftUI?

$
0
0

I'm trying to apply a strikethrough to any tapped Text items in a ForEach loop:

struct BrandListView: View {    @ObservedObject var list: ListObject    var body: some View {        ScrollView {            VStack {                ForEach(list.items) { items in                        Text(item.name)                            .strikethrough(//?)                            .onTapGesture(perform: {                                // on tap, apply strikethrough only to this item.                            })                }            }        }    }}

Is there an easy way to apply a condition using @State var, to track when to apply strikethrough() or not? I'm thinking the only way is to put a property into the listObject that tracks whether it is striked or not, and then use that to apply true/false to the strikethrough() modifier. But that seems like spaghetti code?


Viewing all articles
Browse latest Browse all 88

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>