Stop using Spacer() in SwiftUI
HTML-код
- Опубликовано: 23 май 2023
- 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/flowritescode
👋 Links: flowritesco.de
🛠 Forge: apple.co/3riG8MQ
Affiliate Links ❤
📕 SwiftUI & Combine Books: www.bigmountainstudio.com/a/t...
🔬 Get Reports about your apps: appfigures.com/r/5by3g
📊 Privacy focused analytics: dashboard.telemetrydeck.com/r...
💻 The most powerful mac app for developers: devutils.app/?ref=flo
☕️ Support me: ko-fi.com/flowritescode
If you have any video suggestions please feel free to let me know by a comment.
Get in contact via
Twitter: / flowritescode Наука
Oh! You finally make video about spacer!
I’ve wait for this from you said on short video until now! 😁
Good suggestion for a neat and readable code. Thank you!
Very useful, thanks!
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!! :))
Great to hear!
Great tip! 😃
Great 💡 tips thanks for sharing
Great! Thanks! 🙌
Thanks! Simplified a lot.
Glad it helped!
Nice Star Wars helmets!
And advices are very useful
Great tips! Thanks a lot for the video.
Glad it was helpful!
Very facts i just found that , since i started caring other screen sizes .
Great thanks for sharing your knowledge 📚
My pleasure!
GeometryReader,Stacks and Padding are enough
Thanks! Is using overlay efficient rather than ZStack+VStack?
Since SwiftUI is closed-source, I really don't know how things are implemented under the hood :/
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.
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👍🏼
Totally agree. 4 Spacer() to only keep a Text in a corner seems quite verbose 😅Thanks for the tip
You're welcome!
it's so usefull for me
What's the shortcut to take what you've highlighted and place it within curly braces? I've been doing this by hand 💀
Just use the curly braces, there's no shortcut. Xcode automatically places them around the selected lines :D
what was the short cut you used to add outer {} to a view?
No shortcut, just select mutliple lines and type a {
just male view extension with spacers
Of don’t get what’s wrong with spacer(). Easy to read.
Yup, in some cases it really makes sense. This video just shows an alternative that can be cleaner at times :D
@@FloWritesCode I agree, different scenarios for different needs
@@FloWritesCode Your video is literally called Stop using Spacer() in SwiftUI...
Other screen sizes
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.
How is GeometryReader relevant here?
For all screen sizes spacer() is nightmare . GeometryReader is very powerful for all screen sizes and position .
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.