리스트에서 막히는 부분이 생겨서 빠르게 서치바부터 끝냈다.
https://www.appcoda.com/swiftui-search-bar/
Building a Search Bar in SwiftUI | Mastering SwiftUI
Unlike UIKit, SwiftUI doesn't come with a built-in control for search bar. In this tutorial, let's try to build a SwiftUI version of search bar.
www.appcoda.com
이 사이트를 참고했다.
//
// SearchBar.swift
// SwiftDictionary
//
// Created by Tempnixk on 2022/04/28.
//
import SwiftUI
struct SearchBar: View {
@Binding var text: String
@State private var isEditing = false
var body: some View {
HStack {
TextField("Search ...", text: $text)
.padding(7)
.padding(.horizontal, 25)
.background(Color(.systemGray6))
.cornerRadius(8)
.overlay(
HStack {
Image(systemName: "magnifyingglass")
.foregroundColor(.gray)
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
.padding(.leading, 8)
if isEditing {
Button(action: {
self.text = ""
}) {
Image(systemName: "multiply.circle.fill")
.foregroundColor(.gray)
.padding(.trailing, 8)
}
}
}
)
.padding(.horizontal, 10)
.onTapGesture {
self.isEditing = true
}
if isEditing {
Button(action: {
self.isEditing = false
self.text = ""
}) {
Text("Cancel")
}
.padding(.trailing, 10)
.transition(.move(edge: .trailing))
.animation(.default)
}
}
}
}
struct SearchBar_Previews: PreviewProvider {
static var previews: some View {
SearchBar(text: .constant(""))
}
}
우선 서치바의 틀만 만들어두었고, 나중에 컨텐츠가 생겼을때 단어 목록 추천, 혹은 검색 후 링크까지 구현해야 할 것 같다.
다시 리스트 만드러 가야겠다...
'IOS' 카테고리의 다른 글
SwiftUI Views - Understanding the Syntax (0) | 2022.04.30 |
---|---|
SwiftUI Views - Basic Concepts (0) | 2022.04.29 |
SwiftUI에서 리스트 동적으로 사용하기 (1) (0) | 2022.04.28 |
iOS 개인 프로젝트 시작 (0) | 2022.04.28 |
Xcode 화면 구성 (0) | 2022.04.27 |