Skip to content
Sort List preview
Rendered from the SwiftUI source on this page.

Sort List

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

A single-select list with an iOS checkmark on the active option - sort menus and pickers.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

SortListCard.swift
// Sort List · syxUI · https://syxui.dev/components/sel-sort-list
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

extension View {
    func formaCard(_ pad: CGFloat = 18) -> some View {
        self.padding(pad)
            .background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 20, style: .continuous))
            .overlay(RoundedRectangle(cornerRadius: 20, style: .continuous).stroke(Color.primary.opacity(0.06), lineWidth: 1))
            .shadow(color: .black.opacity(0.05), radius: 14, x: 0, y: 6)
    }
}

// Single-select sort list - iOS checkmark on the active option
struct SortListCard: View {
    @State private var selected = 0
    let options = [("Recommended", "Our top picks for you"),
                           ("Price: Low to High", "Cheapest first"),
                           ("Rating", "Highest rated first"),
                           ("Newest", "Recently added")]
    let accent = Color(red: 0.0, green: 0.48, blue: 1.0)
    var body: some View {
        VStack(spacing: 0) {
            ForEach(Array(options.enumerated()), id: \.offset) { i, o in
                HStack(spacing: 12) {
                    VStack(alignment: .leading, spacing: 2) {
                        Text(o.0).font(.system(size: 15, weight: selected == i ? .semibold : .regular))
                        Text(o.1).font(.system(size: 12)).foregroundStyle(.secondary)
                    }
                    Spacer()
                    if selected == i {
                        Image(systemName: "checkmark").font(.system(size: 15, weight: .bold)).foregroundStyle(accent)
                    }
                }
                .padding(.horizontal, 12).padding(.vertical, 11)
                .contentShape(Rectangle())
                .onTapGesture { selected = i }
                if i < options.count - 1 { Divider() }
            }
        }.formaCard(6)
    }
}
iOS 17 · 1 dependencies

Dependencies

SwiftUI
  • formaCard

Requires iOS 17