Adding Custom Retina Image To TabBar In iOS5
-
I am trying unsuccessfully to get my custom retina images to display in my custom iOS5 TabBar. I have 4 items in my TabBar, I have set the selected/unselected image to [email protected] which has a resolution of 160px x 75px. I figured 4 of these 160px width images would accommodate the 640px retina width nicely. You can view my [email protected] here https://lh4.googleusercontent.com/-afHulbEcxNE/TuPe-YIj91I/AAAAAAAAAII/lCojphAxF9w/s160/contact%2525402x.png I have set all the items programtically as seen below. UIImage *selectedContact = [UIImage imageNamed:@"[email protected]"]; UIImage *unselectedContact = [UIImage imageNamed:@"[email protected]"]; UITabBar *tabBar = self.tabBarController.tabBar; UITabBarItem *item0 = [tabBar.items objectAtIndex:0]; UITabBarItem *item1 = [tabBar.items objectAtIndex:1]; UITabBarItem *item2 = [tabBar.items objectAtIndex:2]; UITabBarItem *item3 = [tabBar.items objectAtIndex:3]; [item0 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact]; [item1 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact]; [item2 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact]; [item3 setFinishedSelectedImage:selectedContact withFinishedUnselectedImage:unselectedContact]; At runtime I can see that the scale is set to 1 Why isn’t the 2 being picked up off the image suffix? The tab bar is huge, and isnt scaled. Please see the simulator screenshot below… https://lh5.googleusercontent.com/-A5oxZprlDhU/TuPfAlG_HQI/AAAAAAAAAIc/mIwHXOPZSrE/s735/simulator.png My other retina images for my app icon and default icon are working. Thoughts? I am driving myself nuts ☺ Thanks in advance.
-
Answer:
JoePasq is wrong, he obviously is not up to date with the latest iOS5 appearance customisation API. Your problem could be that you specified the @2x in the filename, just pass "contact.png" to imagedNamed... [UIImage imageNamed:@ "contact.png"]
Chris at Stack Overflow Visit the source
Other answers
Have you looked at the documentation for customizing the appearance of http://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBar_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40007521-CH3-SW4? You should consult this tutorial by http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5 about using the UIAppearance APIs. His code is this: UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; [[UITabBar appearance] setBackgroundImage:tabBackground]; [[UITabBar appearance] setSelectionIndicatorImage: [UIImage imageNamed:@"tab_select_indicator"]];` Note that the customization happens on the Tab bar, not the tab bar items—assuming it’s the same customization for each one. As http://stackoverflow.com/a/9422148/178805 you do not use @2x in the filename. Prior unedited answer: From the documentation: The images displayed on the tab bar are derived from this image. If this image is too large to fit on the tab bar, it is scaled to fit. The size of an tab bar image is typically 30 x 30 points. The alpha values in the source image are used to create the unselected and selected images—opaque values are ignored. Your icons should be 30x30 px for normal resolution and 60x60 px for retina resolution. They should also be a solid color, the tab bar adds the coloring.
JoePasq
Related Q & A:
- Is there a recommended and consistent way of adding social buttons?Best solution by User Experience
- Is there a way where u can send someone an email using hotmail and adding a small picture in the?Best solution by Yahoo! Answers
- How do I add a custom background image to my Tumblr?Best solution by Yahoo! Answers
- Why do eggs float by adding salt to water?Best solution by Yahoo! Answers
- Adding an external e-mail address to my Yahoo mail?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.