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

Cast Picker

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

A cast / AirPlay device picker list.

Cards · SwiftUI · iOS 17

  • cards
  • swiftui

The actual source

CastCard.swift
// Cast Picker · syxUI · https://syxui.dev/components/media2-cast
// 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)
    }
}

// Cast / AirPlay device picker
struct CastCard: View {
    let devices = [("Living Room TV", "tv", true), ("Kitchen Speaker", "hifispeaker.fill", false), ("Bedroom", "homepod.fill", false)]
    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
            HStack { Image(systemName: "airplayaudio").foregroundStyle(Color(red: 0.0, green: 0.47, blue: 1.0)); Text("Speakers & TVs").font(.system(size: 15, weight: .semibold)); Spacer() }.padding(.bottom, 10)
            ForEach(Array(devices.enumerated()), id: \.offset) { i, dv in
                HStack(spacing: 12) {
                    Image(systemName: dv.1).font(.system(size: 18)).foregroundStyle(dv.2 ? Color(red: 0.0, green: 0.47, blue: 1.0) : Color.secondary).frame(width: 26)
                    Text(dv.0).font(.system(size: 15, weight: dv.2 ? .semibold : .regular))
                    Spacer()
                    if dv.2 { Image(systemName: "checkmark").font(.system(size: 14, weight: .bold)).foregroundStyle(Color(red: 0.0, green: 0.47, blue: 1.0)) }
                }.padding(.vertical, 10)
                if i < devices.count - 1 { Divider() }
            }
        }.formaCard(16).frame(width: 320)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17