自从iOS 6以来,我在我的应用程序中使用自定义样式时遇到了几个问题。我使用自定义字体和几个UIAppearance代理。一个问题是我无法理解的标题在我的UINavigationBar中的错位。在iOS 5中,一切正常且正确对齐。
由于iOS 6已经发布并且自定义样式很常见,我认为这不是一个错误,而是我误解了iOS 6的一些新变化。
我已经搜索文档以查找可以在UIAppearance代理上调用的文本对齐方法,但我找不到这样的方法。
我使用以下代码行在整个应用程序中设置我的UINavigationBar的样式:
由于iOS 6已经发布并且自定义样式很常见,我认为这不是一个错误,而是我误解了iOS 6的一些新变化。
我已经搜索文档以查找可以在UIAppearance代理上调用的文本对齐方法,但我找不到这样的方法。
我使用以下代码行在整个应用程序中设置我的UINavigationBar的样式:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavigationBarBackground"]
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavigationBarBackground"]
forBarMetrics:UIBarMetricsLandscapePhone];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont fontWithName:@"Corbel-Bold" size:14.0], UITextAttributeFont,
nil]];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:[UIColor whiteColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor ceBlueColor], UITextAttributeTextColor,
[UIColor whiteColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"Corbel" size:0.0], UITextAttributeFont,
nil]
forState:UIControlStateNormal];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -3) forBarMetrics:UIBarMetricsDefault];