How to Fix UITaabbaritem UIEdgeInsetsMake on tap to zoom in swift 4

I have a problem if using UITabBarController, center button icon in hold touch an swipe icon make size small, If you have the same problem you can solve like this below



import UIKit

class TabbarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.tabBar.backgroundImage = UIImage()
        self.tabBar.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        self.view.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
   
        let leftVC = UIViewController()
        let centerVC = ForTestPart5VC()
        let rightVC = UIViewController()
       
        leftVC.tabBarItem = UITabBarItem(title: "Left", image: UIImage(named: "e1.png"), tag: 0)
        centerVC.tabBarItem = UITabBarItem(title: "Center", image: UIImage(named: "e2.png"), tag: 1)
        rightVC.tabBarItem = UITabBarItem(title: "Right", image: UIImage(named: "e3.png"), tag: 2)
       
        centerVC.tabBarItem.imageInsets = UIEdgeInsetsMake(7, 0, -6, 0) // Error in here
        viewControllers = [leftVC, centerVC, rightVC]
    }

}

Solution: In UIEdgeInsetsMake top and bottom must be same number setting.

centerVC.tabBarItem.imageInsets = UIEdgeInsetsMake(7, 0, -7, 0) // fix



No comments: