Stop using Spacer() in SwiftUI

Поделиться
HTML-код
  • Опубликовано: 27 ноя 2024
  • Spacer is an easy solution to move Views around on the screen. And while in complex screens it makes sense to use this View, in other situations it makes the code a bit cluttered. Let's explore an alternative using the frame ViewModifier.
    🚀 LaunchBuddy: apple.co/3iFcjjW
    📚 Try CWC+: bit.ly/cwc_flo
    ☕️ Buy me a coffee: ko-fi.com/flow...
    👋 Links: flowritesco.de
    🛠 Forge: apple.co/3riG8MQ
    Affiliate Links ❤
    📕 SwiftUI & Combine Books: www.bigmountai...
    🔬 Get Reports about your apps: appfigures.com...
    📊 Privacy focused analytics: dashboard.tele...
    💻 The most powerful mac app for developers: devutils.app/?...
    ☕️ Support me: ko-fi.com/flow...
    If you have any video suggestions please feel free to let me know by a comment.
    Get in contact via
    Twitter: / flowritescode
  • НаукаНаука

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

  • @nickdalts
    @nickdalts 3 месяца назад +11

    I had absolutely no idea about that autocompletion trick, thanks!

    • @Ugeen-Huge-Jeans
      @Ugeen-Huge-Jeans 2 месяца назад

      Yeah, is there a trick to add a autocompleted parameter to a existing function?

  • @SebastienBarrau
    @SebastienBarrau 2 дня назад +1

    Didn't know about the autocomplete trick!

  • @easybusinessou
    @easybusinessou 3 месяца назад +3

    Great content! Just a small suggestion: it would be even better if the focus was more on the screen code with fewer transitions. Also, keeping your photo in a small circle in the corner works well. Thanks for the valuable insights!

  • @martinq872
    @martinq872 Год назад +2

    Oh! You finally make video about spacer!
    I’ve wait for this from you said on short video until now! 😁

  • @Ugeen-Huge-Jeans
    @Ugeen-Huge-Jeans 2 месяца назад +1

    I noticed that frame() doesn’t work reliably. Spaceer() however does the job all the time.

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

    Great video! What’s the best way to keep the size of the window or at least a minimum size and proportions on visionOS?

  • @yeserguitar
    @yeserguitar Год назад +2

    Good suggestion for a neat and readable code. Thank you!

  • @abdulkarimkhaan
    @abdulkarimkhaan Год назад +1

    I have been creating SwiftUI tutorials from last two months and this is a great piece of advice for aligning texts or view. It will increase readability by keeping code clean.
    Will definitely use this from now onwards.
    Big Thanks!! :))

  • @natgenesis5038
    @natgenesis5038 7 месяцев назад +1

    Very facts i just found that , since i started caring other screen sizes .

  • @alihodroj9559
    @alihodroj9559 11 месяцев назад +1

    Great tips! Thanks a lot for the video.

  • @illyakrit7494
    @illyakrit7494 Год назад +1

    Nice Star Wars helmets!
    And advices are very useful

  • @ramonteiro
    @ramonteiro Год назад +1

    Totally agree. 4 Spacer() to only keep a Text in a corner seems quite verbose 😅Thanks for the tip

  • @fsck-music
    @fsck-music 8 месяцев назад +1

    What's the shortcut to take what you've highlighted and place it within curly braces? I've been doing this by hand 💀

    • @FloWritesCode
      @FloWritesCode  8 месяцев назад +1

      Just use the curly braces, there's no shortcut. Xcode automatically places them around the selected lines :D

  • @holgerflick
    @holgerflick Год назад +2

    Great video! Thank you! Just a note... did you notice the flicker after most of the pans? It is quite unnerving and distracts from the excellent content.

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

      Thanks. I already passed that on to this video‘s editor and it seems to have been a rendering issue in Premiere. Will hopefully be fixed in all videos going forward👍🏼

  • @rahuljamba5846
    @rahuljamba5846 7 месяцев назад +1

    Great thanks for sharing your knowledge 📚

  • @vsemenchenko
    @vsemenchenko Год назад +1

    Thanks! Is using overlay efficient rather than ZStack+VStack?

    • @FloWritesCode
      @FloWritesCode  Год назад +1

      Since SwiftUI is closed-source, I really don't know how things are implemented under the hood :/

  • @DevLiuSir
    @DevLiuSir Год назад +1

    Thanks! Simplified a lot.

  • @KevinChromik
    @KevinChromik Год назад +1

    Very useful, thanks!

  • @swiftandtips
    @swiftandtips Год назад +1

    Great tip! 😃

  • @sunrizz
    @sunrizz Год назад +1

    Great! Thanks! 🙌

  • @rahuljamba5846
    @rahuljamba5846 Год назад +1

    Great 💡 tips thanks for sharing

  • @Scott-oe7dv
    @Scott-oe7dv 6 месяцев назад

    what was the short cut you used to add outer {} to a view?

    • @FloWritesCode
      @FloWritesCode  6 месяцев назад

      No shortcut, just select mutliple lines and type a {

  • @natgenesis5038
    @natgenesis5038 7 месяцев назад +1

    GeometryReader,Stacks and Padding are enough

  • @simonIsDev
    @simonIsDev 8 месяцев назад +1

    it's so usefull for me

  • @CarstenVoss-oh2el
    @CarstenVoss-oh2el 5 месяцев назад

    Sorry but this is title is confusing for new people. This works as long as you use view which tries to take as much space as possible (e.g. Color).
    If one would use your advise and overlay a Text with an Image, one need to set a frame on the text with the correct size and alignment for that frame. Additionally, as the modifier name suggests, the content of the original view could overlapped by the overlay.

  • @ivenprillwitz
    @ivenprillwitz Год назад +1

    Of don’t get what’s wrong with spacer(). Easy to read.

    • @FloWritesCode
      @FloWritesCode  Год назад +1

      Yup, in some cases it really makes sense. This video just shows an alternative that can be cleaner at times :D

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

      @@FloWritesCode I agree, different scenarios for different needs

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

      @@FloWritesCode Your video is literally called Stop using Spacer() in SwiftUI...

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

      Other screen sizes

  • @Hewhogotslapd
    @Hewhogotslapd 7 месяцев назад +1

    Title is misleading for beginners. Geomettery reader is great for the example that you shared, however for more simple UIs Spacer is much easier to use and creates less code complexity. Otherwise great video.

    • @FloWritesCode
      @FloWritesCode  7 месяцев назад +3

      How is GeometryReader relevant here?

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

      For all screen sizes spacer() is nightmare . GeometryReader is very powerful for all screen sizes and position .