16 Mar 2015

UITabBarItem or UIButton image gets scaled when tapping on it continuously

Recently while I am working on an app that was initially developed by one of my friend. In IOS 8, we encountered a bug that when tapping on a tab for 5-6 times, the UITabBarItem image gets scaled itself and when we tap on other tab it restores itself to default satiate. Shown in picture given below

Scaled UITabBarItem image in IOS 8
Scaled UITabBarItem image in IOS 8 

Initially, we thought that it was IOS 8 bug and may be removed itself in recent updates. But I want to give a try to dove this bug, so i searched on GOOGLE and got some answers about scaling problem but they are not relevant to above mentioned problem. Then in one of answers I found that sometime setting image UIEdgeInsets not properly may cause this problem. I checked my code and found that
while creating UITabBarController UIEdgeInsets was not set properly. It was set like

                [item setImageInsets:UIEdgeInsetsMake(4.0, 0, -5.5, 0)];

To make image not scale you have to set equal values to top,bottom,up,down of UIEdgeInsets. So the
the quick fix was

               [item setImageInsets:UIEdgeInsetsMake(5.5, 0, -5.5, 0)];

and now it looks like

Proper image after setting UIEdgeInset
Proper image after setting UIEdgeInset 

Hope it helps you :). Please share your thoughts...

No comments:

Post a Comment