How to use TextEditor in SwiftUI | Bootcamp #36

Поделиться
HTML-код
  • Опубликовано: 30 ноя 2024

Комментарии • 38

  • @damolaadekoya9246
    @damolaadekoya9246 3 года назад +3

    Just subscribed to your channel... your videos are so amazing, one of the best and most detailed SWIFTUI Channel on RUclips

  • @gccount
    @gccount 8 месяцев назад

    Good to see SwiftUI has grown up after 3 years! The TextEditor can customize both background and foreground fully

    • @mareksienczak3135
      @mareksienczak3135 7 месяцев назад

      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!

  • @ojtok79
    @ojtok79 3 года назад +2

    Love your series of swiftui videos!! 😊

  • @rayhaanalykhan
    @rayhaanalykhan 11 месяцев назад +4

    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.

  • @franciscolozada5901
    @franciscolozada5901 Месяц назад +1

    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)

    • @lowlydeveloper3693
      @lowlydeveloper3693 Месяц назад +1

      Thanks! This also works in iOS 17.5 / Xcode 15.4 / SwiftUI 5 ....

  • @vladimirmoor
    @vladimirmoor 3 года назад +1

    Big thanks for this video. Very useful!

  • @ekkogaming5461
    @ekkogaming5461 3 года назад +1

    Thank you for making such great videos with clear explanations, your awesome!

  • @JeckyKA
    @JeckyKA 3 года назад

    your videos are so amazing, thank you!

  • @Stevesvideoshelf
    @Stevesvideoshelf 3 года назад +4

    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.

    • @benhudelson
      @benhudelson Год назад

      This does not work in iOS 14.3. The color is visible behind the rounded corners, but the TextField area background remains default.

  • @ZukuseiStudios
    @ZukuseiStudios 2 года назад

    Another awesome video

  • @TechWithCoffee
    @TechWithCoffee 15 дней назад

    Is there any way to track the cursor position in texteditor?

  • @vortex5896
    @vortex5896 3 года назад +1

    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.

    • @vortex5896
      @vortex5896 3 года назад

      The Idea is to swipe back to a different view, while the editor maintains in the state you left it

    • @SwiftfulThinking
      @SwiftfulThinking  3 года назад +1

      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

    • @vortex5896
      @vortex5896 3 года назад

      @@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!

    • @SwiftfulThinking
      @SwiftfulThinking  3 года назад +1

      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.

    • @vortex5896
      @vortex5896 3 года назад

      You are just great! Thank you so much for being so nice and helping, enjoy youre day man!

  • @kal5211
    @kal5211 Год назад

    My man.

  • @comexbackkid
    @comexbackkid 3 года назад

    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!!!

  • @knowledgeispower4953
    @knowledgeispower4953 10 месяцев назад

    Super bro...🥳

  • @Nunny25
    @Nunny25 3 года назад +1

    Thanks

  • @AlexandrTej
    @AlexandrTej Год назад

    Hello. How I can realize text field on iOS 13? :) Maybe it's possible with TextField?)

  • @guzmangonzalezrodrigo6268
    @guzmangonzalezrodrigo6268 3 года назад

    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!! 🥺

    • @SwiftfulThinking
      @SwiftfulThinking  3 года назад

      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?

  • @rasheed1andrew
    @rasheed1andrew 3 года назад

    how do you make the placeholder text disappear on tapping the text field.

    • @SwiftfulThinking
      @SwiftfulThinking  3 года назад

      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.

    • @rasheed1andrew
      @rasheed1andrew 3 года назад

      @@SwiftfulThinking 🤔. Also I had sent you an email from your website. I’ll love to get a feedback from you

  • @yogeshbhatt3806
    @yogeshbhatt3806 2 года назад

    I think TextEditor is not available in ios 13

  • @notorioustofu3482
    @notorioustofu3482 2 месяца назад

    Hiding the scrollContentBackground and applying .background works as well
    TextEditor(text: $textEditorText)
    .frame(height: 250)
    .scrollContentBackground(.hidden)
    .background(
    Color(uiColor: .lightGray)
    .cornerRadius(8)
    )