Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selected state of tab bar icon in IOS 7

I'm having fun learning to build my first iPhone app and wonder if someone would kindly point me in the right direction.

I have basically added in custom icons for my tab bar (IOS 7). Now I want to add in a custom selected state icon for each of these. How would I do this?

Thanks

Shell

like image 412
user2889540 Avatar asked Oct 17 '13 12:10

user2889540


2 Answers

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

like image 73
MrAlek Avatar answered Sep 27 '22 18:09

MrAlek


Here is the swift solution based on @MrAlek's solution, create a custom UITabBarItem

import UIKit

@IBDesignable
class YourTabBarItem: UITabBarItem {

    @IBInspectable var selectedImageName:String!{
        didSet{
            selectedImage = UIImage(named: selectedImageName)
        }
    }
}

and in interface builder, change the class of the tab bar item and you will see the Selected Image Name attribute, just specify your selected image name there. I reckon @IBInspectable is using the runtime attribute.

enter image description here

like image 21
codingrhythm Avatar answered Sep 27 '22 19:09

codingrhythm