I have created a tab controller programmatically.
Now, I wanted to add images to the different tabs, for which I used :
self.tabBarItem.image = [UIImage imageNamed:@"Sample_Image.png"];
The problem is Sample_image is larger in size than is required by tab.
So just want to know how can I clip the image to fit into tabs.
Try this piece of code as this will resize the required image and return an
UIImage
instance with30x30
size (size required forUITabbar
).Add This method
If your icons are not fitting in the tabbar then copy the same image into 2x image asset or 3x image asset instead of 1x asset. It will fit properly and it's worked for me
Rename your image to
Sample_Image@2x.png
. This is called pixel doubling for the Retina Display.Without the @2x iOS doesn't know that it should apply a scale factor and it will be used as it is and though it should be halved.
In reality there should be:
Sample_Image png (45 px or so)
Sample_Image@2x.png so you say only: