Empty the title of the UINavigationController and use TitleView to create space.

Asked 2 years ago, Updated 2 years ago, 138 views

I would like to solve the problem of creating space between titleView and return by emptying the return button characters in the UINavigationController with title=" and setting the search bar such as navigationItem.titleView=UISearchBar().Does anyone know a good solution?

Symptom screenshot

ios swift objective-c uikit uinavigationcontroller

2022-09-30 18:21

1 Answers

I don't know if it will be solved, but I can reduce the gap by making the return button myself.
(Verified in Xcode 7.2.1/iOS 9.2 simulator environment)

Back Button Comparison Image

The source code looks like this.

import UIKit

classSecondViewController:UIViewController {

    override func viewDidLoad(){
        super.viewDidLoad()

        // Add Search Bar
        let sb = UISearchBar()
        navigationItem.titleView=sb

        // Create a UIBarButtonItem with a standard image
        let img = UIImage(named: "back-image")
        navigationItem.leftBarButtonItem=UIBarButtonItem(image:img, style: .Plain, target:self, action:"backMenu")
    }

    /// Return to previous screen
    funcbackMenu(){
        dismissViewControllerAnimated(true, completion:nil)
    }
}


2022-09-30 18:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.