在iOS7中栏标题太长时,隐藏UINavigationBar后退按钮标题

时间:2013-11-20 11:05:25

标签: ios objective-c uinavigationbar

我遇到了问题但无法解决。我会尝试描述这个问题,所以:

UINavigationBar的标题不长时 - 情况是这样的:

enter image description here

但如果栏的标题包含更多字符 - 它会隐藏后退按钮的标题,如下图所示:

enter image description here

它是iOS7中的标准UINavigationBar行为吗?可能有一些方法可以解决这个问题?无论如何iOS6情况要好得多 - 在那里我找不到这样的问题。

enter image description here

1 个答案:

答案 0 :(得分: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