Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationBar back button title is hidden when the bar title is too long in iOS7

I have a problem and can't solve it. I'll try to describe the issue, so:

when the title of the UINavigationBar is not so long - the situation is like this:

enter image description here

but if the title of the bar contains more characters - it hides the title of the back button as u can see on the next screenshot:

enter image description here

Is it a standard UINavigationBar behaviour in iOS7? May be there are some ways to solve this? Anyway in iOS6 the situation is much better - there I can't find any problem like this.

enter image description here

like image 276
ShurupuS Avatar asked Nov 20 '13 11:11

ShurupuS


People also ask

How to hide back button title in navigation controller swift?

While you are pushing 2nd controller from 1st controller, put self. navigationItem. title = "" in viewWillDisappear of 1st controller. It hides back button title from 2nd controller.

How to set back button title in navigation bar swift?

Change The Back Button Title In The Previous View Controller You can also just set the title of the previous view controller and iOS will automatically set that to the back button of the view controller. Now on the next view controller that push on the navigation stack, it will have this title as its back button.

How do I customize the back button on my iPhone?

Check that you have the latest version of iOS on your iPhone 8 or later. Go to Settings > Accessibility > Touch, and tap Back Tap. Tap Double Tap or Triple Tap and choose an action. Double or triple tap on the back of your iPhone to trigger the action you set.


1 Answers

Simple fix:

Create one view with label and set that view as a title view to the navigation controller

// creating title view 
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
    // Adding label with custom frame
    UILabel *labelForTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];

    [labelForTitle setCenter:titleView.center];
    [labelForTitle setText:@"sfdfagd ggjhdgfjhadsgfjasgdhfgasdjfgajsdgfjashgdjhfasjdfsadjgfhsadghf"];

    [titleView addSubview:labelForTitle];
    
     // setting title view for the navigation controller.
    [self.navigationItem setTitleView:titleView];

output will be like this :

enter image description here

like image 72
Ganapathy Avatar answered Nov 02 '22 22:11

Ganapathy