“back” text displayed in iOS7 UINavigationBar when view title is long

后端 未结 4 1622
萌比男神i
萌比男神i 2020-12-16 21:54

In my application,I need to show the previous viewController title to current viewController back title.

Its working perfectly in iOS6.

In iOS7,automaticall

相关标签:
4条回答
  • 2020-12-16 22:05

    iOS 7 will automatically replace your back button title with "Back" or even remove the title altogether in order to fit the title of current navigation item. You probably shouldn't try to do anything about it except maybe try and make your titles shorter.

    if you want to make short title you can do as below

    self.title = @"SOME REALLY LONG NAVIGATION BAR TITLE";
    UILabel* label=[[UILabel alloc] initWithFrame:CGRectMake(0,0, 200, 40)];
    label.text=self.navigationItem.title;
    label.adjustsFontSizeToFitWidth=YES;
    self.navigationItem.titleView=label;
    
    0 讨论(0)
  • 2020-12-16 22:18

    Due to low reputation I cannot add a comment so I'm posting an answer while this is not actually an answer.

    But,

    self.navigationController.navigationBar.topItem.title = @"";
    

    which is written in one of the answers, is equivalent to:

    self.title = @"";
    
    0 讨论(0)
  • 2020-12-16 22:22

    try this,

    self.navigationController.navigationBar.topItem.title = @"";
    
    0 讨论(0)
  • 2020-12-16 22:25

    In iOS 7 you will not be allowed to set the back button's title to be any longer than 11 characters.

    To avoid changing the title of the view controller, but to change the back button's title, you need to do this:

    In the previous view controller (the one that will have the next view controller pushed on top of it) you need to set the backBarButtonItem like so:

    /**
     *  Notifies the view controller that its view was added to a view hierarchy.
     *
     *  @param  animated                    If YES, the view was added to the window using an animation.
     */
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    
        self.title = @"My Title Can Be Long";
    
        self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"ThisIsLimit"
                                                                                 style:UIBarButtonItemStylePlain
                                                                                target:nil
                                                                                action:nil];
    }
    

    Now, when the next view controller is pushed on top of it, the back button will be whatever title you put in the backBarButtonItem.

    0 讨论(0)
提交回复
热议问题