I tried to implement search bar in UIViewController by embedding UISearchBar as subview in navigationItem title view. After implementing, i am seeing some space before search bar in navigation.
Code i added to embed search bar in navigation title :
let searchBar = self.searchBar!
searchBar.showsCancelButton = true
searchBar.sizeToFit()
searchBar.delegate = self;
searchBar.barTintColor = UIColorFromRGB(0xCFDFE7)
searchBar.clipsToBounds = true
searchBar.layer.cornerRadius = 6
searchBar.layer.borderWidth = 1.0
searchBar.layoutIfNeeded()
if let button = self.getCancelButtonFromSearchBarView(searchBar) {
button.setTitle("Close", forState: UIControlState.Normal)
}
var barWrapper = UIView(frame:searchBar.bounds)
barWrapper.addSubview(searchBar)
self.navigationItem.titleView = barWrapper
Search bar appearance in view controller : space is marked in red color on left side of search bar.
Could someone suggest how can i adjust search bar to left without space?