外観プロキシを使用してナビゲーション バーの戻るボタンをカスタマイズし、画像とテキストの属性も設定しています。すべて正常に動作しますが、戻るボタンのテキストが中央揃えではありません。
これが私のコードです。
UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease];
UIImage *buttonBack32 = [[UIImage imageNamed:@"NavigationBackButton"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 5)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack32 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
UITextAttributeTextColor,
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"xxx" size:16.0],
UITextAttributeFont,
nil]
forState:UIControlStateNormal];
self.navigationItem.backBarButtonItem = backButton;
フォント サイズを「0.0」に設定すると、テキストのサイズが小さすぎて、中央揃えになりません。
助けてくれてありがとう。