Home Avoid the searchBar to expand after use
Reply: 0

Avoid the searchBar to expand after use

user1086 Published in May 28, 2018, 5:02 am

I am making a function for a header view with 2 views on top of a tableView. I want to give each UIView half of the width of the tableview. It works fine at the first loading, but after I first use the search bar, it expands automatically and it fills 100% of the tableview width.

func headerView() {

var textfieldView = UITextField(frame: CGRect(x: 200, y: 0, width: 200, height: 40))
searchController.searchBar.frame = CGRect(x: 0, y: 0, width: 200, height: 40)


func searchbar() {

searchController.searchResultsUpdater = self as UISearchResultsUpdating
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
searchController.searchBar.setBackgroundImage(#imageLiteral(resourceName: "Rectangle"), for: UIBarPosition.any, barMetrics: UIBarMetrics.default)


I would also appreciate help for setting a dynamic width as half of the tableview width (tableview.width / 2 ?) instead of a fixed one (200pixels)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309964 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO