WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Guys tell me how to implement something like this menu?

Forums > SwiftUI

struct HeaderNavigationView: View {
    //var actionMenu: () -> Void
    //var title: String
    //var subtitle: String

    var body: some View {
        HStack {
            ZStack(alignment: Alignment(horizontal: .leading, vertical: .center)) {
                HStack {
                    VStack {
                        Text("title")
                            .font(.system(size: 20, weight: .light, design: .default))
                            .foregroundColor(.black)
                        Text("subtitle")
                            .font(.system(size: 14, weight: .regular, design: .default))
                            .foregroundColor(.black)
                    }
                }
            }
            Spacer()
            Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/) {
                Image(systemName: "chevron.left")
                    .foregroundColor(.black)
            }
        }
        .frame(width: .infinity)
        .border(Color.red, width: /*@START_MENU_TOKEN@*/1/*@END_MENU_TOKEN@*/)
    }
}

(http://joxi.ru/l2ZYoOzu7ZNyom)

1      

so far I was able to implement like this

struct HeaderNavigationView: View {
    var actionMenu: () -> Void
    var title: String
    var subtitle: String

    var body: some View {
        ZStack {
            GeometryReader { g in
                HStack {
                    Button(action: actionMenu ) {
                        Image(systemName: "chevron.left")
                            .foregroundColor(.white)
                    }
                    VStack {
                        Text(title)
                            .font(.system(size: 20, weight: .light))
                            .foregroundColor(.white)
                        Text(subtitle)
                            .font(.system(size: 14, weight: .regular))
                            .foregroundColor(.powderBlue)
                    }
                    .frame(width: g.size.width)
                    .offset(x: g.safeAreaInsets.leading - 20, y: 0)
                }
            }
        }
        .frame(height: 40, alignment: .top)
        .padding(.horizontal, 15)
    }
}

1      

Hacking with Swift is sponsored by Emerge

SPONSORED Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.