UISearchBar increases navigation bar height in iOS 11
I got black line under NavigationBar with SearchBar in iOS 11 in two cases:
when i pushed another ViewControllers from ViewController with UISearchBar
when i dismissed ViewController with UISearchBar with "drag right to dismiss"
My solution was: adding this code to my ViewController with UISearchBar:
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.navigationController.view setNeedsLayout]; // force update layout
[self.navigationController.view layoutIfNeeded]; // to fix height of the navigation bar
}
Swift 4 Update
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.view.setNeedsLayout() // force update layout
navigationController?.view.layoutIfNeeded() // to fix height of the navigation bar
}
iOS 11 UISearchBar in navigation bar
Look answer in UIPercentDrivenInteractiveTransition. It's using for update UIViews during UINavigationController transition in persentage value.
Other words, depends on how much UINavigationController already opened next view controller or move backwards views will have different appearance.
This value will help you update your search bar (alpha, width, etc.)
UISearchBar Height Automatic Size Change Swift
This is latest swift4.2 code and latest functionality of search bar just put this function in controller and call from viewDidLoad.
func setupNavBar() {
self.title = "Controller title"
self.navigationController?.navigationBar.prefersLargeTitles = false
self.navigationController?.navigationItem.largeTitleDisplayMode = .always
let searchController = UISearchController(searchResultsController: nil)
searchController.searchBar.delegate = self
navigationItem.searchController = searchController
}
Large navigation bar custom height
Ok, I found this way:
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.minimumLineHeight = 200
let attributes: [NSAttributedString.Key: Any] = [ .paragraphStyle: paragraphStyle]
let navigationBar = navigationController?.navigationBar
if #available(iOS 13, *) {
if let appearance = navigationBar?.standardAppearance {
appearance.largeTitleTextAttributes = attributes
navigationBar?.standardAppearance = appearance
navigationBar?.scrollEdgeAppearance = appearance
}
} else {
navigationBar?.largeTitleTextAttributes = attributes
}
ios11: UISearchBar in Navigation Bar
I believe the search bar and the nav bar are two separate elements so your gradient is only effecting one. You can set them both to clear and then put another view or label element behind (add constraints) with the gradient you're looking for.
for the searchBar you want to set both the barTintColor and the backgroundImage with the following code.
override func viewDidLoad() {
self.searchBar.barTintColor = UIColor.clear
self.searchBar.backgroundImage = UIImage()
self.navBar.backgroundColor = UIColor.clear
}
Related Topics
How to Create Layout Constraints Programmatically
One Step Affine Transform for Rotation Around a Point
Objective C: Downloading File with Progress Bar
How to Use Nslocalizedstring Function with Variables in Swift
Scrollview Gesture Recognizer Eating All Touch Events
Capturing and Storing a Picture Taken with the Camera into a Local Database/Phonegap/Cordova/Ios
Uidatepicker Select Month and Year
Custom Init for Uiviewcontroller in Swift with Interface Setup in Storyboard
What Is "Self" Used for in Swift
Xcode Quits Unexpectedly Every Time I Open My Project
How to Delete Wkwebview Cookies
How to Opt Your iPad App Out of Multitasking on iOS 9
Ios9 Does Not Load Insecure Resources from a Secure Page (Ssl/Https)
How to Detect If a Video File Was Recorded in Portrait Orientation, or Landscape in iOS
Xcode 6.1 Missing Required Architecture X86_64 in File
How to Hide Keyboard in Swift on Pressing Return Key
How to Initialize/Instantiate a Custom Uiview Class with a Xib File in Swift