在iOS7中,当导航栏标题过长时,导航栏返回按钮的标题会被隐藏。

5

我有一个问题无法解决。我会尽量描述这个问题:

UINavigationBar的标题不是很长时,情况就像这样:

enter image description here

但是如果栏目的标题包含更多字符,则会隐藏返回按钮的标题,如下面的屏幕截图所示:

enter image description here

这是否是iOS7中标准的UINavigationBar行为?也许有一些方法可以解决这个问题?在iOS6中,情况要好得多-我找不到任何类似的问题。

enter image description here


1
在我看来,这是可以的,并且应该相信苹果公司对用户体验的决策。如果返回按钮没有任何相关属性,那么尝试使用自定义的返回按钮,使其外观与默认按钮相同。 - Evgeniy S
[[UIBarButtonItem alloc]initWithCustomView:yourView] - Neil Galiaskarov
1个回答

7

简单的解决方法:

创建一个包含标签的视图,并将该视图设置为导航控制器的标题视图。

// 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];

输出结果如下所示:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接