I found an issue with TextField in SwiftUI. I used a TextField in my app and set a placeholder that is a link like ‘www.abcdefg.com’. However, the placeholder color is blue instead of gray. I don’t know how to change the placeholder text color or disable link detection for the TextField. Does anyone know how to fix this? Thanks!
2
Answers
This is because of markdown. You can try this approach using
prompt
from iOS 15, now you’re able to change the color, font, etc… to whatever you want.The
TextField
initialiser might be using thisText
initialiser under the hood to create the label. This detects markdown and renders it as such. You should useTextField.init(text:label:)
that allows you to pass in anyView
as a label instead. Then you can useText.init(verbatim:)
to force it to not treat the text as markdown.Alternatively, you can use backslashes to escape the dots in the URL, so SwiftUI no longer detects it as a URL.
Other solutions here may also work.