Skip to content
Location Search preview
Rendered from the SwiftUI source on this page.

Location Search

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

A place-search results list.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

SearchLocation.swift
// Location Search · syxUI · https://syxui.dev/components/search-location
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

func searchField(_ placeholder: String) -> some View {
    HStack(spacing: 8) { Image(systemName: "magnifyingglass").font(.system(size: 15)).foregroundStyle(.secondary); Text(placeholder).font(.system(size: 16)).foregroundStyle(.secondary); Spacer() }.padding(.horizontal, 12).padding(.vertical, 11).background(Color.primary.opacity(0.06), in: RoundedRectangle(cornerRadius: 12, style: .continuous))
}

// Location search
struct SearchLocation: View {
    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
            searchField("Search for a place").padding(.bottom, 8)
            ForEach(Array([("Blue Bottle Coffee", "0.3 mi"), ("Central Park", "1.2 mi"), ("Grand Central", "1.8 mi")].enumerated()), id: \.offset) { i, l in
                HStack(spacing: 12) { Image(systemName: "mappin.circle.fill").font(.system(size: 22)).foregroundStyle(Color(red: 0.90, green: 0.24, blue: 0.28)); VStack(alignment: .leading, spacing: 2) { Text(l.0).font(.system(size: 15, weight: .medium)); Text(l.1).font(.system(size: 12)).foregroundStyle(.secondary) }; Spacer() }.padding(.vertical, 9)
                if i < 2 { Divider() }
            }
        }.frame(width: 320)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17