Stop using Spacer in SwiftUI (and what to use instead)
Вставка
- Опубліковано 15 лип 2024
- Stop using Spacer in SwiftUI (and what to use instead)
Mentoring 👉 rebeloper.com/mentoring
In this video, we're going to be talking about the Spacer in SwiftUI and how to use it correctly. We'll also be discussing some alternatives to the Spacer, which will better suit your needs.
If you're using the Spacer in your SwiftUI layouts, then you may be experiencing some issues. In this video, we'll be discussing the problems with the Spacer and how to properly use the alternatives to fix them. By the end of the video, you'll know how to properly use the Spacer and avoid common issues.
00:00 INTRO
00:30 SWIFTUI SPACER EXAMPLE
01:22 SWIFTUI LAYOUT EXPLAINED
02:40 SPACER WITH COLOR IN SWIFTUI
03:48 SPACER MINIMUM LENGTH
05:01 MENTORING
05:36 TWO SPACERS IN SWIFTUI
06:12 FRAME WITH ALIGNMENT
08:46 ALIGNMENT VIEW EXTENSION
13:00 WHERE TO GO NEXT
→ PLAYLIST:
Learn SwiftUI 👉 • World's Shortest Swift...
DO YOU WANT TO ME TO WORK ON YOUR PROJECT?
HIRE ME → rebeloper.com/hire-us/
TOOLS I RECOMMEND:
→ rebeloper.com/tools
__________
Get in touch:
→ support@rebeloper.com
SUBSCRIBE to weekly tips & tutorials for building iOS apps!
→ ua-cam.com/users/rebeloper?su...
GitHub: github.com/rebeloper/
Hire me: rebeloper.com/hire-us/
LinkedIn: / rebeloper
My Blog: rebeloper.com/blog
Follow me on Instagram: / rebeloper
Twitter: / rebeloper
______
#rebeloper - Наука та технологія
Thanks, Alex! This looks much better than all the Spacer() additions everywhere!! Good advice!!
Glad you like it!
Next find out why MVVM is BAD for SwiftUI - Use MVC Instead! (Yes, MVC) 👇
ua-cam.com/video/2D05dGo3jB4/v-deo.html&ab_channel=Rebeloper-RebelDeveloper
That's very useful, thanks!
Glad it was helpful!
Next find out why MVVM is BAD for SwiftUI - Use MVC Instead! (Yes, MVC) 👇
ua-cam.com/video/2D05dGo3jB4/v-deo.html&ab_channel=Rebeloper-RebelDeveloper
Thanks so much it’s very useful now I’m thinking about We have to do more practicing to handle to be more flexible like constrain mechanism, what if I need to set this center y with constant up or down the center it will be magic extension
Try to avoid auto-layout logic from UIKit. Think of push-out and pull-in views and container views instead.
Next find out why MVVM is BAD for SwiftUI - Use MVC Instead! (Yes, MVC) 👇
ua-cam.com/video/2D05dGo3jB4/v-deo.html&ab_channel=Rebeloper-RebelDeveloper
Are there any drawbacks to setting the max width/height to infinity?
Not that I know of.
Next find out why MVVM is BAD for SwiftUI - Use MVC Instead! (Yes, MVC) 👇
ua-cam.com/video/2D05dGo3jB4/v-deo.html&ab_channel=Rebeloper-RebelDeveloper
Its definitely opinionated if this is a better way. You won't be able to achieve every layout using only frame.
And you can achieve the same using (no need for introducing one more alignment enum):
extension View {
@ViewBuilder func alignment(_ alignment: Alignment) -> some View {
self.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: alignment)
}
}
Great input. Agreed with both.
Next find out why MVVM is BAD for SwiftUI - Use MVC Instead! (Yes, MVC) 👇
ua-cam.com/video/2D05dGo3jB4/v-deo.html&ab_channel=Rebeloper-RebelDeveloper
Very helpful!! I have a quick question.
hey thanks a lot. Another question that’s simple. Where is the best place for a noob to get on a swift Forum and leave questions and get answers right away - as opposed to something like stack overflow where it seems like you have to build up a reputation and get “status “before you get respected for your questions.
Thanks.
My first question would be, why do I have a view, that when I put a form in there it works perfectly. When I remove the form, when I click a button, the action code of the other button gets fired. It’s the weirdest thing from my point of view. I don’t understand. Is there something special about a form that would cause button that you didn’t click to be executed?
I put a break Point on button 2s code. I clicked button one. And it stops on the code of button two, after executing, the code on button one. What in the world is going on?
Maybe it's a bug in Form. Are you using Xcode 15?
For quick questions-answers I suggest joining my community: store.rebeloper.com/community
Next find out why MVVM is BAD for SwiftUI - Use MVC Instead! (Yes, MVC) 👇
ua-cam.com/video/2D05dGo3jB4/v-deo.html&ab_channel=Rebeloper-RebelDeveloper
Yes, I’m x code 15 beta seven.
I found some hack or if you put a modifier on it it fixes it.
I’m looking for a community/mentorship for free. I’m a hobbyist developer. I can’t afford to pay for anything.
Thanks a lot for getting back to me
Great. The community or mentorship come with a fee. UA-cam is free though :)
Next watch Mastering SwiftUI's Night Mode: Unlock Next-Level App Design 👇
ua-cam.com/video/Qm1Sf0oOwfI/v-deo.html&ab_channel=Rebeloper-RebelDeveloper
Don't forget that views inherit .frame from parent views. So if you have views within views, and it won't change alignment, make sure to check the parent view(s)
Great advice. Forgot about this. Thank you for sharing.
Next find out why MVVM is BAD for SwiftUI - Use MVC Instead! (Yes, MVC) 👇
ua-cam.com/video/2D05dGo3jB4/v-deo.html&ab_channel=Rebeloper-RebelDeveloper
wow where is the proof?
It's just a preference for readable and maintainable code.
Next find out why MVVM is BAD for SwiftUI - Use MVC Instead! (Yes, MVC) 👇
ua-cam.com/video/2D05dGo3jB4/v-deo.html&ab_channel=Rebeloper-RebelDeveloper