Kevin ABRIOUX
Kevin ABRIOUX

Reputation: 17695

iOS UITabBar selectionIndicatorImage Y position

I have this spec:

enter image description here

But, i have this:

enter image description here

I have this code:

self.mTabBar.selectionIndicatorImage = UIImage(named: "footer-blue-line")

How can I set the Y position for the selectionIndicatorImage?

Upvotes: 3

Views: 2168

Answers (3)

Dannie P
Dannie P

Reputation: 4622

Here you go. You just need to set class of Tab Bar to this class in the interface builder

class MyCustomTabBar: UITabBar
{
    var didInit = false
    override func layoutSubviews()
    {
        super.layoutSubviews()

        if didInit == false
        {
            didInit = true
            for subview in subviews {
                // can't hookup to subviews, so do layer.sublayers
                subview.layer.addObserver(self, forKeyPath: "sublayers", options: .New, context: nil)
            }
        }
    }

    deinit
    {
        for subview in subviews
        {
            subview.layer.removeObserver(self, forKeyPath: "sublayers")
        }
    }

    override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>)
    {
        // layer.delegate is usually the parent view
        if let l = object as? CALayer, tbButton = l.delegate as? UIView where tbButton.window != nil
        {
            for v in tbButton.subviews
            {
                if String(v.dynamicType) == "UITabBarSelectionIndicatorView" {
                    v.setYOrigin(3)
                }
            }
        }
    }
}

Upvotes: 0

Pritam
Pritam

Reputation: 165

http://s18.postimg.org/c5bjg501h/line.png

Use the image given on the link on the place of "footer-blue-line".

Upvotes: 0

user3752049
user3752049

Reputation: 167

Why aren't you using a single "selected" image that has a blue line below it ?

Upvotes: 3

Related Questions