Question

I have this code who, put an image inside a barItem:

frist.tabBarItem.image = [UIImage imageNamed:@"1.jpg"];

It works perfectly, but the image does not appear, because the image have 256x256 pixels, I've heard that the image must have a 30x30 pixels, but I don't wanna to change resolution manually, I want to change this per code, is possible?

Was it helpful?

Solution

Try something like this:

UIImage *image = [UIImage imageNamed:@"1.jpg"];

[image drawInRect:CGRectMake(0, 0, 30, 30)];

frist.tabBarItem.image = image;

OTHER TIPS

let moreVC = storyboard.instantiateViewController(withIdentifier: "MoreVC")
moreVC.tabBarItem = UITabBarItem(title: "More", image: UIImage(named: "fifth"), tag: 5)
moreVC.tabBarItem.imageInsets.top = 7
moreVC.tabBarItem.imageInsets.bottom = 7
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top