DEV Community

loading...

Do Good Daily Day 6

swlkr profile image Sean Walker ・1 min read

πŸ“… 09/17/2019
πŸ”₯ 6 day streak
πŸ“± Do Good Daily
πŸ’° $0.99 price
πŸ€‘ 0 sales
⌚️ 5.5 hours spent
πŸ’» 37 files changed 554 additions(+) 81 deletions(-)
βœ… Today's goal: Finish up rough versions of intro views

SwiftUI is better than web development

When it works it really works. Today the preview feature was working well and I managed to breeze through a few more static screens with simple buttons. It's insane that all it takes to make something very custom looking is ~70 lines of code per screen, if you can even call it code. It definitely makes me wonder what the heck we're doing out there in web development land. Anyway, I did learn a few SwiftUI tricks that I thought I'd share

SwiftUI full screen background image

var body: some View {
        VStack {
        }
        .background(
            Image("bg")
            .resizable()
            .scaledToFill()
            .edgesIgnoringSafeArea(.all)
        )
}

That's all it takes. Either that or a ZStack and put the image as the first child.

SwiftUI center an image

Or anything really. It's funny I was messing around with this problem for a while but I came up with something pretty decent, assuming you only have one thing to center

var body: some View {
        VStack {
             Spacer()

             Image("bg")

             Spacer()
        }

}

There's some more code with some other goodies but there's always tomorrow.

Discussion (0)

pic
Editor guide