Добавить searchBar как subview navigationBar
.
navigationController?.navigationBar.isTranslucent = false
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.barStyle = .black
navigationController?.navigationBar.barTintColor = UIColor.red
navigationController?.navigationBar.shadowImage = UIImage()
title = "User profile";
let searchBar = UISearchBar()
searchBar.placeholder = "Search"
searchBar.frame = CGRect(x: 0, y: 0, width: (navigationController?.view.bounds.size.width)!, height: 64)
searchBar.barStyle = .default
searchBar.isTranslucent = false
searchBar.barTintColor = UIColor.red
searchBar.backgroundImage = UIImage()
view.addSubview(searchBar)