0

I want to set padding (or resizing) for image used for tabBarItem. So in the controller I write the below code:

  - (instancetype)init
    {
        self = [super init];
        if (self) {
            UIImage *i = [UIImage imageNamed:@"groups_icon"];
            self.tabBarItem.image = i;
            self.tabBarItem.imageInsets = UIEdgeInsetsMake(3, 3, 3, 3);
        }
        return self;
    }

But after each time I press the tabBarItem the image is going to be smaller. How can I set it to do it only one time? I test it in the viewDidLoad and viewWillApear and the result is the same.

Also it is noticeable that I could not set the image for tabBarItem before using the relevant controller, when I initialized the UITabBarController.

Soheil Novinfard
  • 1,358
  • 1
  • 16
  • 43

1 Answers1

0

Unfortunately, you can't... This is either a bug, or imageInsets is very poorly documented. You can only use imageInsets to move the image around, and the sum of insets of the same axis must always be 0. That is to say top and bottom insets must be opposite values as well as left and right insets.

If you want a smaller image, you're going to have to create one yourself (using photoshop or similar software), add it to your assets and use this pre-shrinked image.

deadbeef
  • 5,409
  • 2
  • 17
  • 47