1

I am creating sample project in swift. I have added tabbar controller in this project. I have set selectionIndicatorImage to highlight selected tab. I'm getting extra padding in selected tab.

Here is code for highlight selected tab :

let numberOfItems = CGFloat(tabBar.items!.count)
let tabBarItemSize = CGSize(width: (tabBar.frame.width / numberOfItems), height: tabBar.frame.height)
tabBar.selectionIndicatorImage = UIImage.imageWithColor(color: UIColor(red:123.0/255.0, green:31.0/255.0, blue:162.0/255.0, alpha:1.0), size: tabBarItemSize).resizableImage(withCapInsets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))

With the use of above code I'm getting output like this,

enter image description here

Any suggestion would be appreciated.

Thanks.

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75

1 Answers1

-1

There is some default spacing while you select any UITabBar. To overcome below are the two solutions you can go with it.

Solution 1:

You can change UITabBar x-origin slightly to left:

self.tabBarController!.tabBar.frame = self.tabBarController!.tabBar.frame.insetBy(dx: -2, dy: 0)

Solution 2:

self.tabBarController!.tabBarItem.imageInsets = UIEdgeInsetsMake(0, -2, 0, 0)
Sohil R. Memon
  • 9,404
  • 1
  • 31
  • 57