3

I have two ViewControllers inside a tab bar controller. In interface builder, I've applied image insets (5, 5, 5, 5) to the tab bar icons to get their sizes how I want them. Everything looks great when I initially run the simulator, but when I tab to the second ViewController, both tab bar icons automatically resize to the default (0, 0, 0, 0). When I tab back to return to the first ViewController, both icons remain trapped at default size with no insets.

Note: My icon images are .pdf files in XCassets folder (set as single vector Scale Factor). I've seen other threads which suggest "balancing" the insets (5 for top, -5 for bottom). But this would COMPRESS the image by 5 away from the top and STRETCH it 5 toward the bottom. I don't see how that's meant to balance the image size.

If anyone knows what code will set the insets at runtime, maybe I could use that instead of setting insets in interface builder? Thanks in advance.

dimery2006
  • 335
  • 1
  • 5
  • 13

1 Answers1

0

Reading the documentation, UIBarItem (superclass of UITabBarItem) has the property imageInset, and you can access the tab bar items via self.tabBarController.tabBar.items.

Without testing it myself, I think you may have an issue with the insets getting reset when the shading changes (because of selection).

Thus, you may find that every time you change selection (and that can be detected via delegate I think), you'll need to reset the insets to the desired size.

Alternatively, you might find that just customizing the source image to the desired final appearance may be easier.

sschale
  • 5,168
  • 3
  • 29
  • 36