Skip to content
Drawer Menu preview
Rendered from the SwiftUI source on this page.

Drawer Menu

From syxUI — written for both platforms, not translated between them.

A side-drawer menu with a profile header.

Navigation · SwiftUI · iOS 17

  • navigation
  • swiftui

The actual source

DrawerMenu.swift
// Drawer Menu · syxUI · https://syxui.dev/components/nav2-drawer
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let navBlue = Color(red: 0.0, green: 0.47, blue: 1.0)

// Side drawer menu
struct DrawerMenu: View {
    @State private var sel = 0
    let items = [("house.fill", "Home"), ("tray.fill", "Inbox"), ("star.fill", "Starred"), ("gearshape.fill", "Settings")]
    var body: some View {
        VStack(alignment: .leading, spacing: 4) {
            HStack(spacing: 10) {
                Circle().fill(navBlue.opacity(0.2)).frame(width: 40, height: 40).overlay(Text("JW").font(.system(size: 14, weight: .semibold)).foregroundStyle(navBlue))
                VStack(alignment: .leading, spacing: 1) { Text("James W.").font(.system(size: 15, weight: .semibold)); Text("Pro plan").font(.system(size: 12)).foregroundStyle(.secondary) }
                Spacer()
            }.padding(.bottom, 12)
            ForEach(Array(items.enumerated()), id: \.offset) { i, it in
                HStack(spacing: 12) { Image(systemName: it.0).font(.system(size: 16)).foregroundStyle(sel == i ? navBlue : .secondary).frame(width: 24); Text(it.1).font(.system(size: 15, weight: sel == i ? .semibold : .regular)); Spacer() }.padding(.vertical, 10).padding(.horizontal, 10).background(sel == i ? navBlue.opacity(0.1) : .clear, in: RoundedRectangle(cornerRadius: 10)).onTapGesture { sel = i }
            }
        }.padding(16).frame(width: 250).background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 18)).overlay(RoundedRectangle(cornerRadius: 18).stroke(Color.primary.opacity(0.06)))
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17