自從iOS 6以來,我在我的應用程序中使用自定義樣式有幾個問題。我使用自定義字體和幾個UIAppearance
代理。我無法理解的問題是UINavigationBar中的標題錯位。在iOS 5中一切正常,並正確對齊。自iOS6以來UINavigationBar中未對齊的標題
由於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。我只在使用自定義字體時看到問題。因此,作爲一個實驗,如果您使用標準字體,您可能想嘗試查看問題是否消失。看到我關於這個主題的問題在這裏:http://stackoverflow.com/questions/12504556/uinavigationbar-title-behaves-oddly-when-specifying-a-font-using-uiappearance-w – Snips
它適用於標準字體。剛試過了。 – wiseindy