尽管通过外观代理全局改变您的UINavigationBar标题,例如:
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:0.5 forBarMetrics:UIBarMetricsDefault];
如何为单个视图控制器定义标题的垂直高度,我期望看起来像这样:
[self.navigationBar setTitleVerticalPositionAdjustment:0.5 forBarMetrics:UIBarMetricsDefault];
但不幸的是不起作用。我试图调整我的标题的特定视图控制器的垂直位置,而不影响其他视图控制器的UINavigationBar标题位置。
答案 0 :(得分:1)
您可以使用appearanceWhenContainedIn:
选择器为每个单独的UIViewController设置外观。它看起来像这样......
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerOne class], nil] setTitleVerticalPositionAdjustment:0.3 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerTwo class], nil] setTitleVerticalPositionAdjustment:0.5 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerThree class], nil] setTitleVerticalPositionAdjustment:0.7 forBarMetrics:UIBarMetricsDefault];
<强>更新强>
如何通过创建StyleManager
类来使用它的示例:
@implementation StyleManager
+ (void)setApplicationStyle
{
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerOne class], nil] setTitleVerticalPositionAdjustment:0.3 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerTwo class], nil] setTitleVerticalPositionAdjustment:0.5 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[ViewControllerThree class], nil] setTitleVerticalPositionAdjustment:0.7 forBarMetrics:UIBarMetricsDefault];
// Other appearnce styling here...
}
@end
创建StyleManager
后,您只需在AppDelegate
中使用它:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[StyleManager setApplicationStyle];
}
请告诉我这是否适合您。