Skip to content
Selection Sheet preview
Rendered from the SwiftUI source on this page.

Selection Sheet

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

A single-select list sheet with Done.

Cards · SwiftUI · iOS 17

  • cards
  • swiftui

The actual source

SelectSheet.swift
// Selection Sheet · syxUI · https://syxui.dev/components/sheet-select
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

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

func shCard<C: View>(_ w: CGFloat, radius: CGFloat = 18, @ViewBuilder _ c: () -> C) -> some View {
    c().frame(width: w).background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: radius, style: .continuous)).overlay(RoundedRectangle(cornerRadius: radius, style: .continuous).stroke(Color.primary.opacity(0.07), lineWidth: 1)).shadow(color: .black.opacity(0.05), radius: 12, y: 5)
}

// Selection list sheet
struct SelectSheet: View {
    @State private var sel = 1
    let opts = ["English", "Spanish", "French", "German"]
    var body: some View {
        shCard(320, radius: 22) {
            VStack(spacing: 0) {
                HStack { Text("Language").font(.system(size: 17, weight: .semibold)); Spacer(); Text("Done").font(.system(size: 16, weight: .semibold)).foregroundStyle(shBlue) }.padding(16)
                Divider()
                ForEach(Array(opts.enumerated()), id: \.offset) { i, o in
                    HStack { Text(o).font(.system(size: 15)); Spacer(); if sel == i { Image(systemName: "checkmark").font(.system(size: 14, weight: .bold)).foregroundStyle(shBlue) } }.padding(.horizontal, 16).padding(.vertical, 12)
                    if i < opts.count - 1 { Divider() }
                }
            }
        }
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17