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

Autocomplete

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

A search field with a suggestions dropdown.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

AutocompleteField.swift
// Autocomplete · syxUI · https://syxui.dev/components/inp-autocomplete
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

// Autocomplete with suggestions
struct AutocompleteField: View {
    var body: some View {
        VStack(spacing: 0) {
            HStack { Image(systemName: "magnifyingglass").foregroundStyle(.secondary); Text("San Fr").font(.system(size: 16)); Spacer() }.padding(.horizontal, 14).padding(.vertical, 13)
            Divider()
            ForEach(["San Francisco, CA", "San Francisco Bay", "San Fernando, CA"], id: \.self) { s in
                HStack { Image(systemName: "mappin.circle").font(.system(size: 14)).foregroundStyle(.secondary); Text(s).font(.system(size: 14)); Spacer() }.padding(.horizontal, 14).padding(.vertical, 10)
            }
        }.overlay(RoundedRectangle(cornerRadius: 12, style: .continuous).stroke(Color.primary.opacity(0.15), lineWidth: 1)).clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous)).frame(width: 300)
    }
}
iOS 17 · No dependencies

Dependencies

SwiftUI
No external dependencies

Requires iOS 17