iPhone 的纵向模式下导航栏标题未居中

Navigation bar title is not centred in iPhone's portrait mode

我创建了一个 ViewController 使用大小为 wAny 和 hAny 的 Xib 文件,并且我使用了 autolayaout 和约束来适应 UI 所有设备和所有方向。

一切正常,但是当我在 运行 应用上 iPhone 时,导航栏的纵向模式标题未居中,而将其旋转到横向模式时,标题居中。

我使用以下代码设置标题

self.title = @"Download Schedule";

已经尝试过: 我尝试将较小字体大小的自定义 UI 标签设置为导航栏的标题视图,但我仍然将其放在左侧。

这是我的右键代码

 //add right bar button for more options
    UIView *navBarButtonsView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    UIBarButtonItem *item0 = [UIBarButtonItem negativeSpacerWithWidth:5];
    UIButton *moreButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    [moreButton setBackgroundImage:[UIImage imageNamed:@"ic_web"] forState:UIControlStateNormal];
    [moreButton addTarget:self action:@selector(addNewSchedule) forControlEvents:UIControlEventTouchDown];
    [navBarButtonsView addSubview:moreButton];

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:navBarButtonsView];
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:item0, backButton, nil];

还有一些事情正在发生 - 一些你没有告诉我们的事情。我怀疑您设置 rightButtonItems 的方式有问题,以至于右边的 space 上有不可见的按钮。我只能通过故意使右侧按钮非常宽来重现此问题:

所以我怀疑您将右侧按钮的宽度应用得过大,或者右侧的 space 中有额外的不可见右侧按钮项目。