How to remove spacing between tab bar items when using the "fill" value on the "item position" option?
I've tried the following:
let tabBarController = window!.rootViewController as! UITabBarController
tabBarController.tabBar.itemSpacing = 0
let numberOfItems = CGFloat(tabBarController.tabBar.items!.count)
let tabBarItemSize = CGSize(width: tabBarController.tabBar.frame.width / numberOfItems, height: tabBarController.tabBar.frame.height)
tabBarController.tabBar.selectionIndicatorImage = UIImage.imageWithColor(color: UIColor.secondaryHighlight(), size: tabBarItemSize).resizableImage(withCapInsets: UIEdgeInsets.zero)
for item in tabBarController.tabBar.items! {
item.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0)
}
extension UIImage {
class func imageWithColor(color: UIColor, size: CGSize) -> UIImage {
let rect: CGRect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
color.setFill()
UIRectFill(rect)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}
}
This result is always this (note the green line on the left of the first tab bar item):