【发布时间】:2012-09-29 15:40:24
【问题描述】:
从 iOS 6 开始,我在应用程序中使用自定义样式时遇到了几个问题。我使用自定义字体和几个UIAppearance 代理。我无法理解的一个问题是我的 UINavigationBar 中的标题未对齐。在 iOS 5 中,一切正常并且正确对齐。
由于 iOS6 已经发布并且自定义样式并不少见,我认为这不是错误,而是我对 iOS6 的一些新变化的误解。
我在文档中搜索了一个文本对齐方法来调用 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];
【问题讨论】:
-
恐怕不是答案,但我想说我没有看到不同的问题,尽管只有 iOS 5。我只在使用自定义字体时看到问题。因此,作为一个实验,您可能想尝试看看如果您使用标准字体,问题是否会消失。请参阅我关于此主题的问题:stackoverflow.com/questions/12504556/…
-
它适用于标准字体。刚试了一下。
标签: ios fonts uinavigationbar uiappearance