SwiftUI multicolor and multipurpose textfield


Have a problem here, trying to achieve such functionality as on screen shot.
As you can see, there is 2 types of interaction.

  1. User can tap on time, like 15 minutes, and a TimePicker will appear. And on weekday – another view will appear.
  2. User can tap on purpose and input his own text between ‘on’ and ‘each’ words. Like usual, keyboard will appear, cursor appears – user is ready to input his text in place. ‘answering questions on stackoverflow’ becomes just a placeholder.

It not hard to implement this using just Text, like this one:

Group {
                Text("I would like to spend ")
                    .foregroundColor(.primary) +
                Text("15 minutes")
                    .foregroundColor(.pink)
                    .underline() +
                Text(" on ")
                    .foregroundColor(.primary) +
                Text("answering questions on stackoverflow")
                    .foregroundColor(.teal)
                    .underline() +
                Text(" each ")
                    .foregroundColor(.primary) +
                Text("weekday")
                    .foregroundColor(.green)
                    .underline()
            }

But in such case there is no way to add interactivity, like taps and Text input.

The other way can be probably handled with Markdown?

Thanks for advance.

enter image description here

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img