CustomView を使用しないのはなぜですか?
のようにUIBarButtonItem initWithCustomView:
次に、ボタン (グラフィックを提供する必要があります) がどのように表示されるかを正確に制御できます。
クリックに応答するようにカスタム ビューを設定する方法について説明している関連する質問を次に示します。
編集:
エラーチェックに関しては、ちょっとやりすぎたコードがありますが、あなたの設定には何かが間違っていると確信しています。これを使えば、それが何であるかを知ることができるかもしれません。
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
if(btn)
{
[btn setBackgroundImage:[UIImage imageNamed:@"19-gear.png"] forState:UIControlStateNormal];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:btn];
if(barButton)
{
if(self.navigationController)
{
if(self.navigationController.navigationBar)
{
if(self.navigationController.navigationBar.topItem)
{
self.navigationController.navigationBar.topItem.leftBarButtonItem = barButton;
} else {
NSLog( @"why is topItem null?");
}
} else {
NSLog( @"navigationBar appears to be null");
}
} else {
NSLog( @"navigationController is null");
}
} else {
NSLog(@"did not create UIBarButtonItem");
}
} else {
NSLog( @"did not create UIButton");
}