Skip to content
Time Range preview
Rendered from the SwiftUI source on this page.

Time Range

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

Departure / return time-range sliders.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

PickerTimeRange.swift
// Time Range · syxUI · https://syxui.dev/components/picker-time-range
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

let pkPurple = Color(red: 0.55, green: 0.40, blue: 0.90)

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)
    }
}

struct PickerTimeRange: View { var body: some View { VStack(alignment: .leading, spacing: 16) { VStack(alignment: .leading, spacing: 8) { HStack { Text("Departure").font(.system(size: 14, weight: .semibold)); Spacer(); Text("12:00 am – 10:00 am").font(.system(size: 13)).foregroundStyle(.secondary) }; GeometryReader { g in ZStack(alignment: .leading) { Capsule().fill(Color.primary.opacity(0.1)).frame(height: 3); Capsule().fill(pkPurple).frame(width: g.size.width * 0.4, height: 3); Circle().fill(pkPurple).frame(width: 16, height: 16).offset(x: -8); Circle().fill(pkPurple).frame(width: 16, height: 16).offset(x: g.size.width * 0.4 - 8) } }.frame(height: 16) }; VStack(alignment: .leading, spacing: 8) { HStack { Text("Return").font(.system(size: 14, weight: .semibold)); Spacer(); Text("5:00 pm – 12:00 am").font(.system(size: 13)).foregroundStyle(.secondary) }; GeometryReader { g in ZStack(alignment: .leading) { Capsule().fill(Color.primary.opacity(0.1)).frame(height: 3); Capsule().fill(pkPurple).frame(width: g.size.width * 0.35, height: 3).offset(x: g.size.width * 0.6); Circle().fill(pkPurple).frame(width: 16, height: 16).offset(x: g.size.width * 0.6 - 8); Circle().fill(pkPurple).frame(width: 16, height: 16).offset(x: g.size.width * 0.95 - 8) } }.frame(height: 16) } }.formaCard().frame(width: 320) } }
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17