中心导航栏标题垂直

Mil*_*ilo 8 objective-c uinavigationbar ios

我有一个简单的故事板,其中包含一个带有静态表视图控制器的导航控制器.我添加了一个视图控制器,并通过push segue将其连接到其中一个单元.我注意到的一件事是导航栏标题没有与后退按钮垂直居中UIBarButtonItem.这是现在看起来的图像.在此输入图像描述

请注意,它全部与底部对齐.我想要的是,一种方法是向下移动标题或向上移动按钮.如果向上移动按钮,也应移动后退按钮箭头,并允许返回主表视图.

这是我用来UIBarButtonItem在视图控制器中设置字体的代码(如果它有帮助):

[clearButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"ChalkboardSE-Regular" size:15], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];

以下是我用来为app delegate中的后退按钮设置字体的方法didFinishLaunchingWithOptions::

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont fontWithName:@"ChalkboardSE-Regular" size:15]}forState:UIControlStateNormal];

erk*_*diz 8

您可以使用以下命令向下移动标题: [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:(float) forBarMetrics:UIBarMetricsDefault];


cle*_*ght 7

适用于iOS 8+的SWIFT版本

  self.navigationController!.navigationBar.setTitleVerticalPositionAdjustment(adj, forBarMetrics: .Default)
Run Code Online (Sandbox Code Playgroud)
  • self 是一个UIViewController:

注意:考虑指定其他条形度量选项的调整,以优化横向模式和紧凑设备的偏移,因为在所有位置的所有手机上,一个偏移可能看起来不正确.