How to change width of searchBar's scope?

71 Views Asked by At

Here is my picture when I run my program.

Xcode14.3.1 swift5.8.1

I have some child view controllers in my navigation controller. In one of these, a back button was automatically created, and I added a UIBarButtonItem on the right side of the navigation bar. I also programmatically created a search bar and set it as the title view.

However, when I display the scope bar of the search bar, it doesn't expand fully. The back button and the right barButtonItem seem to be interrupting it. Is it possible to make the search bar's scope expand to the full width?

import UIKit

class ResultSearchViewController: UIViewController {
    
    @IBOutlet weak var rightBarButton: UIBarButtonItem!
    @IBOutlet var searchBar: UISearchBar!

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationItem.titleView = searchBar
        searchBar.showsScopeBar = true
  

    }
    
}
0

There are 0 best solutions below