TextEditor(text: $textEditorText) .frame(height: 250) .foregroundStyle(.black.opacity(0.8)) .scrollContentBackground(.hidden) // we cannot change the background color of 'TextEditor' directly, first we have to hide the default background using this code, then apply background. .background(.gray.opacity(0.5)) // To see this .clipShape(.rect(cornerRadii: .init(topLeading: 10, bottomLeading: 10, bottomTrailing: 10, topTrailing: 10))) // cornerRadius is deprecated.
In the current version of swiftUI (6) (2024) this two modifiers allows to change the backcolor of the textEditor, without affecting the foregroundColor property .scrollContentBackground(.hidden) .background(.orange)
Great as always! after some digging it seems like the TextEditor has some baggage from UIKit? which may be why you cannot set its background color directly. However if you put: init() {UITextView.appearance().backgroundColor = .clear} in the main view struct, say just above the state variables, then you can use .background(Color.x) as you normally would.
Hey, it is possible to save a TextEditor as itself? I mean not having to set another text = TextEditor. E.g. as on my iphone. When using the note function there and editing a new note, i can just swipe back to the overwiev of notes and the textEditor is safed.
Hi Vortex! So in this situation, you don't actually save a TextEditor, but rather save the Text that inside. And when a user goes to a screen with a TextEditor, you can initialize it with the saved text (instead of a blank string that we used in the video). I did another video on initializers here: ruclips.net/video/su0KLQq0JM0/видео.html
@@SwiftfulThinking make sense! Is the data/string also saved after closing the app ? Or do i have to do somerhing else than initializing the texteditor with the saved text. thank you so much!
In order to save data between sessions (open/closing apps) you need to save the information somewhere. For small pieces of data such as a single String, you can use AppStorage (ruclips.net/video/zyuSUrfelw8/видео.html). To save a lot of data, you will need something more advanced, such as Core Data or an external database.
I've been plowing through your Bootcamp videos, thank you so much for putting these together. Quick question with TextEditor(), can this be used in a Form{}? Seems to not be letting me change the placeholder text when inside a Form. Thanks again!!!
hey nick, thanks for the video!! My question is, what if I want to make a size variable text field, so that way it adjusts to all screen sizes of devices?? I've tried many ways but i cant figure it out!! 🥺
Hi Rodrigo! The TextEditor in the video should automatically resize for different devices. I'm not sure what the issue you are running into is. If you need the TextField to rotate with the device, you will need to put it inside a GeometryReader. Does this help?
Hey Rasheed, unfortunately, the TextEditor doesn't have the same features as the TextField. You can add some custom logic if you want to check if text == "placeholder" and then update the text.
Hiding the scrollContentBackground and applying .background works as well TextEditor(text: $textEditorText) .frame(height: 250) .scrollContentBackground(.hidden) .background( Color(uiColor: .lightGray) .cornerRadius(8) )
Just subscribed to your channel... your videos are so amazing, one of the best and most detailed SWIFTUI Channel on RUclips
Thank you Damola! Glad you're enjoying :)
Good to see SwiftUI has grown up after 3 years! The TextEditor can customize both background and foreground fully
I wouldn't say so. Have you tried typed more than 40 lines in TextEditor? The text in the control starts to jump up and down. That is preposterous!
Love your series of swiftui videos!! 😊
Thank you for watching! :)
TextEditor(text: $textEditorText)
.frame(height: 250)
.foregroundStyle(.black.opacity(0.8))
.scrollContentBackground(.hidden) // we cannot change the background color of 'TextEditor' directly, first we have to hide the default background using this code, then apply background.
.background(.gray.opacity(0.5)) // To see this
.clipShape(.rect(cornerRadii: .init(topLeading: 10, bottomLeading: 10, bottomTrailing: 10, topTrailing: 10))) // cornerRadius is deprecated.
In the current version of swiftUI (6) (2024) this two modifiers allows to change the backcolor of the textEditor, without affecting the foregroundColor property
.scrollContentBackground(.hidden)
.background(.orange)
Thanks! This also works in iOS 17.5 / Xcode 15.4 / SwiftUI 5 ....
Big thanks for this video. Very useful!
You're welcome!
Thank you for making such great videos with clear explanations, your awesome!
Hey Ekko Gaming! Thanks for watching :)
your videos are so amazing, thank you!
Great as always! after some digging it seems like the TextEditor has some baggage from UIKit? which may be why you cannot set its background color directly. However if you put: init() {UITextView.appearance().backgroundColor = .clear} in the main view struct, say just above the state variables, then you can use .background(Color.x) as you normally would.
This does not work in iOS 14.3. The color is visible behind the rounded corners, but the TextField area background remains default.
Another awesome video
Thanks again!
Is there any way to track the cursor position in texteditor?
Hey, it is possible to save a TextEditor as itself? I mean not having to set another text = TextEditor. E.g. as on my iphone. When using the note function there and editing a new note, i can just swipe back to the overwiev of notes and the textEditor is safed.
The Idea is to swipe back to a different view, while the editor maintains in the state you left it
Hi Vortex! So in this situation, you don't actually save a TextEditor, but rather save the Text that inside. And when a user goes to a screen with a TextEditor, you can initialize it with the saved text (instead of a blank string that we used in the video). I did another video on initializers here: ruclips.net/video/su0KLQq0JM0/видео.html
@@SwiftfulThinking make sense! Is the data/string also saved after closing the app ? Or do i have to do somerhing else than initializing the texteditor with the saved text. thank you so much!
In order to save data between sessions (open/closing apps) you need to save the information somewhere. For small pieces of data such as a single String, you can use AppStorage (ruclips.net/video/zyuSUrfelw8/видео.html). To save a lot of data, you will need something more advanced, such as Core Data or an external database.
You are just great! Thank you so much for being so nice and helping, enjoy youre day man!
My man.
I've been plowing through your Bootcamp videos, thank you so much for putting these together. Quick question with TextEditor(), can this be used in a Form{}? Seems to not be letting me change the placeholder text when inside a Form. Thanks again!!!
Super bro...🥳
Thanks
Hello. How I can realize text field on iOS 13? :) Maybe it's possible with TextField?)
hey nick, thanks for the video!!
My question is, what if I want to make a size variable text field, so that way it adjusts to all screen sizes of devices?? I've tried many ways but i cant figure it out!! 🥺
Hi Rodrigo! The TextEditor in the video should automatically resize for different devices. I'm not sure what the issue you are running into is. If you need the TextField to rotate with the device, you will need to put it inside a GeometryReader. Does this help?
how do you make the placeholder text disappear on tapping the text field.
Hey Rasheed, unfortunately, the TextEditor doesn't have the same features as the TextField. You can add some custom logic if you want to check if text == "placeholder" and then update the text.
@@SwiftfulThinking 🤔. Also I had sent you an email from your website. I’ll love to get a feedback from you
I think TextEditor is not available in ios 13
Hiding the scrollContentBackground and applying .background works as well
TextEditor(text: $textEditorText)
.frame(height: 250)
.scrollContentBackground(.hidden)
.background(
Color(uiColor: .lightGray)
.cornerRadius(8)
)