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

Action Sheet

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

An iOS action sheet with a Cancel button.

Cards · SwiftUI · iOS 17

  • cards
  • swiftui

The actual source

ActionSheet.swift
// Action Sheet · syxUI · https://syxui.dev/components/sheet-action
// 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)
}

// Action sheet
struct ActionSheet: View {
    var body: some View {
        VStack(spacing: 8) {
            shCard(320) {
                VStack(spacing: 0) {
                    ForEach(Array([("square.and.arrow.up", "Share"), ("bookmark", "Save"), ("pencil", "Edit")].enumerated()), id: \.offset) { i, a in
                        HStack(spacing: 12) { Image(systemName: a.0).font(.system(size: 17)).foregroundStyle(shBlue).frame(width: 24); Text(a.1).font(.system(size: 16)); Spacer() }.padding(.horizontal, 16).padding(.vertical, 14)
                        if i < 2 { Divider() }
                    }
                }
            }
            shCard(320) { Text("Cancel").font(.system(size: 17, weight: .semibold)).foregroundStyle(shBlue).frame(maxWidth: .infinity).padding(.vertical, 15) }
        }
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17