Reputation: 2277
I know how to add back navigation button with image or change the tile but I haven't seen any example with background image and its title (@"back"
).
Can I add a custom UIButton with custom background image and title?
Upvotes: 2
Views: 2349
Reputation: 11
I'm not sure what you mean by (@back) but here is how I was able to get an image in the back button and the the UINavigationBar:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"myLogo.png"] forBarMetrics:UIBarMetricsDefault];
UIImage *backButton = [[UIImage imageNamed:@"HeaderTest.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(12, 12, 12, 12)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
This is an ios 5 solution. Thank you to these sources: http://www.whypad.com/posts/ios-5-problem-setting-image-for-uinavigationbar/1011/
Upvotes: 1
Reputation: 12910
This, what I finally did in my code actually works!!! Just update "forState" and "barMetrics" values for different appearances.
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"myImage"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Upvotes: 3