iosswiftswiftui

Detecting click on each word in a paragraph in SwiftUI


I have web game and here is it's screenshot

newsgamer

As you can see it can detect clicks on each word as they are just spans inside a flex layout.

I want to have a similar functionality in SwiftUi as I am building an iOS app for this game.

I tried GridView, HStacks, they just seem to have limitations

HStack will only render in one line, Gridview wants to have a minimum predefined width.

I want something that is smoothly rendered and each word is clickable


Solution

  • You search for WrappingHStack

    https://github.com/dkk/WrappingHStack

    you're able to split text to words and implement click function on each element

    enter image description here