14.3. Phase 3: Place Search and Navigate
Setting up the Bottom Search Sheet
//
// MapView.swift
// App14
//
// Created by Sakib Miazi on 6/14/23.
//
import UIKit
import MapKit
class MapView: UIView {
//codes omitted...
var buttonSearch:UIButton!
override init(frame: CGRect) {
//codes omitted...
setupButtonSearch()
initConstraints()
}
//codes omitted...
func setupButtonSearch(){
buttonSearch = UIButton(type: .system)
buttonSearch.setTitle(" Search places... ", for: .normal)
buttonSearch.titleLabel?.font = UIFont.boldSystemFont(ofSize: 24)
buttonSearch.setImage(UIImage(systemName: "magnifyingglass.circle.fill"), for: .normal)
buttonSearch.layer.backgroundColor = UIColor.darkGray.cgColor
buttonSearch.tintColor = .white
buttonSearch.layer.cornerRadius = 10
buttonSearch.layer.shadowOffset = .zero
buttonSearch.layer.shadowRadius = 4
buttonSearch.layer.shadowOpacity = 0.7
buttonSearch.translatesAutoresizingMaskIntoConstraints = false
buttonSearch.isHidden = true
self.addSubview(buttonSearch)
}
func initConstraints(){
NSLayoutConstraint.activate([
//codes omitted...
buttonSearch.bottomAnchor.constraint(equalTo: buttonCurrentLocation.bottomAnchor),
buttonSearch.centerXAnchor.constraint(equalTo: self.safeAreaLayoutGuide.centerXAnchor),
buttonSearch.heightAnchor.constraint(equalTo: buttonCurrentLocation.heightAnchor)
])
}
//codes omitted...
}
Bottom Search Sheet
SearchViewController.swift
SearchBottomSheet.swift
SearchTableViewCell.swift
SearchTableViewManager.swift
Displaying the Bottom Search Sheet

Searching Nearby Places

Displaying the search results in the search table view
Setting an observer from the bottom search sheet
Posting notification from Map Screen

Code so far
Previous14.2. Phase 2: Annotations and Accessories for a certain placeNext14.4. Phase 4: Display Searched Places on Map
Last updated

