The TextField in SwiftUI isn't very customizable, but I tried to make it look like it.
struct TestView: View {
@State private var text: String = ""
var body: some View {
ZStack{
TextField("input", text: $text)
.foregroundColor(.clear)
HStack(spacing: 0){
let strings = text.split(separator: " ", omittingEmptySubsequences: false)
ForEach(strings.indices, id: \.self){i in
Text(strings[i])
.background(
Color(.sRGB, red: 0.847, green: 0.917, blue: 0.992)
.cornerRadius(5)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(Color(.sRGB, red: 0.745, green: 0.866, blue: 0.988))
)
)
.padding(.horizontal, 2)
}
Spacer()
}
}
}
}
TextField
is too restrictive, so make the color clear
to make it invisible and display it as you like.
The cursor disappears because the text is covered from above. To prevent this, for example, the background color of the text should be transparent, but I gave up because it was difficult to match the colors.