Skip to content
Language Picker preview
Rendered from the SwiftUI source on this page.

Language Picker

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

A language list with a checkmark on the active choice.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

LanguagePickerCard.swift
// Language Picker · syxUI · https://syxui.dev/components/sel-language
// 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)
    }
}

// Language picker list
struct LanguagePickerCard: View {
    @State private var sel = 0
    let blue = Color(red: 0.0, green: 0.47, blue: 1.0)
    let langs = [("English", "English"), ("Español", "Spanish"), ("Français", "French"), ("Deutsch", "German")]
    var body: some View {
        VStack(spacing: 0) {
            ForEach(Array(langs.enumerated()), id: \.offset) { i, l in
                HStack(spacing: 12) {
                    Image(systemName: "globe").font(.system(size: 15)).foregroundStyle(.secondary).frame(width: 24)
                    VStack(alignment: .leading, spacing: 1) {
                        Text(l.0).font(.system(size: 15, weight: .medium))
                        Text(l.1).font(.system(size: 12)).foregroundStyle(.secondary)
                    }
                    Spacer()
                    if sel == i { Image(systemName: "checkmark").font(.system(size: 14, weight: .bold)).foregroundStyle(blue) }
                }.padding(.vertical, 10).contentShape(Rectangle()).onTapGesture { sel = i }
                if i < langs.count - 1 { Divider() }
            }
        }.formaCard(14).frame(width: 320)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17