Reputation: 17695
I have this spec:
But, i have this:
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
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
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
Reputation: 167
Why aren't you using a single "selected" image that has a blue line below it ?
Upvotes: 3