Selected Status of Tab Bar Icon in iOS 7

I have fun learning how to create my first iPhone app and wonder if someone would kindly point me in the right direction.

Basically I added custom icons for my tab bar (iOS 7). Now I want to add a custom selected status icon for each of them. How can I do it?

thanks

Shell

+6
source share
6 answers

As in Xcode 6, you can do this by default in Interface Builder. There is no need for any custom subclasses or categories as before.

+18
source

On iOS7 you should install selectedImage

 tabBarItem.selectedImage = selectedImage; tabBarItem.image = unselectedImage; 

Keep in mind that selectedImage not available in iOS6.
Use – setFinishedSelectedImage:withFinishedUnselectedImage: if you need to support iOS6.

+4
source

Here is a quick solution based on @MrAlek solution, create a custom UITabBarItem

 import UIKit @IBDesignable class YourTabBarItem: UITabBarItem { @IBInspectable var selectedImageName:String!{ didSet{ selectedImage = UIImage(named: selectedImageName) } } } 

and in the interface builder, change the class of the tab bar item and you will see the Selected Image Name attribute, just specify its name for the selected image. I believe that @IBInspectable uses the runtime attribute.

enter image description here

+4
source

See my more complete answer at fooobar.com/questions/211375 / ...

Often your tab will have a navigation controller stack, so you'll need the following

 - (void)viewDidLoad { [super viewDidLoad]; ... [self.navigationController.tabBarItem setSelectedImage:[UIImage imageNamed:@"MySelectedIcon.png"]]; } 

If you have only one view controller in a tab without a UINavigationController shell, you should use

 [self.tabBarItem setSelectedImage:[UIImage imageNamed:@"MySelectedIcon.png"]]; 
+2
source

Use as shown below and solve the image problem in iOS7:

 [self.navigationController.tabBarItem setSelectedImage:[[UIImage imageNamed:@"MySelectedIcon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 
+1
source

You can use the custom sub method to launch tabBarItem.

 -(instancetype)initWithTitle:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage 
-1
source

Source: https://habr.com/ru/post/956167/


All Articles