问题
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?
回答1:
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];
回答2:
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/
http://iosdevelopertips.com/user-interface/ios-5-customize-uinavigationbar-and-uibarbuttonitem-with-appearance-api.html
来源:https://stackoverflow.com/questions/8181781/back-navigationitem-with-title-background-image