UINavigationBar 标题文本部分出现在屏幕上

UINavigationBar title text partially appears on screen

我正在以编程方式创建一个 UINavigationBar,它按 iOS 7 中的预期显示。但是,在 iOS 8.x 中,UINavigationBar 中的所有文本都没有t 出现在屏幕范围内。我的假设之一是这与自动布局有关。

//ViewControllerRootHomeCenter.m
_navBar = [[UINavigationBar alloc] init];
_navBar.frame = CGRectMake(0,0, self.view.frame.size.width, 64);

// add hambuger menu
//...etc etc

[self.view addSubView:_navbar];

首先,确保您没有对导航栏的宽度进行硬编码。

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];

其次,如果启用了自动布局,请确保没有冲突约束。如果它没有启用,那么我不明白为什么你会遇到这个问题。

你也可以试试这样获取屏幕宽度:

CGRect frame = (CGRect){0,0,CGRectGetWidth([[UIScreen mainScreen]bounds]),64);

也许它会解决您的问题。