Objective-c – Custom back button view

iphoneobjective c

I'm trying to change the back button to a custom one. If I create a UIBarButtonItem with just a custom title, that works fine. However if I create one with a custom view, the button doesn't show, rather the default back button shows. Any ideas ?

UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
backBtn.frame = CGRectMake(0, 0, 51, 31);
[backBtn setImage:[UIImage imageNamed:@"nav_btn_back.png"] forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *back = [[[UIBarButtonItem alloc] initWithCustomView:backBtn] autorelease];
self.navigationItem.backBarButtonItem = back;   

Best Answer

Not sure why that's not working. However I realized that I can just set this custom button as a leftBarButtonItem for my view

Related Topic