0
votes

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. enter image description here

Could someone suggest how can i adjust search bar to left without space?

1
UISearchBar(frame: CGRectMake(-5, 0, 320, 44)) use this tips might be it will help youHarish
@harish, thank you so much. It worked. u saved my dayRajeev

1 Answers

0
votes

From comment of @harish,

UISearchBar(frame: CGRectMake(-5, 0, 320, 44)) use this tips might be it will help you – harish