0

I am having an issue with Tabbar Controller that images of tab bar item is blur in retina iOS devices . Here is my code for images in tab bar item is following:

float itemW;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);

float  itemH= self.tabBarController.tabBar.frame.size.height;
itemW=  self.tabBarController.tabBar.frame.size.width;
//itemW=itemW+self.tabBarController.tabBar.frame.origin.x*2;

 if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){

     itemW=itemW/5;
     NSLog(@"WIDTH OF %f%f",itemW,itemH);
    // itemH= 60 ;
 }
 else{
     itemW=itemW/5-40;
     //itemH= self.tabBarController.tabBar.frame.size.height;
 }

CGSize newSize = CGSizeMake(itemW,itemH);
CGSize newSize1 = CGSizeMake(itemW,itemH);
NSArray *tabImg=[[NSArray alloc] initWithObjects:@"pc.png",@"fav.png",@"cont01.png",@"dial01.png",@"tool01.png",nil];
NSArray *unSelect=[[NSArray alloc] initWithObjects:@"pc01.png",@"fav01.png",@"cont.png",@"dial.png",@"tool.png",nil];
    //tabbar item images
int k=[self.tabBarController.tabBar.items count];
for (int i=0; i<k; i++) {

    UIImage *imageName=[UIImage imageNamed:[tabImg objectAtIndex:i]];
    UIImage *imageName1=[UIImage imageNamed:[unSelect objectAtIndex:i]];
    UIGraphicsBeginImageContext(newSize);
    [imageName drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();


    UIGraphicsBeginImageContext(newSize1);
    [imageName1 drawInRect:CGRectMake(0, 0, newSize1.width, newSize1.height)];

    UIImage *newImage1 = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();


   [[[self.tabBarController.viewControllers objectAtIndex:i] tabBarItem]setFinishedSelectedImage:newImage withFinishedUnselectedImage:newImage1];
}

And size of all images are 96X80 pixels. Now I am not getting what cause blurred images. Help me to resolve this problem.

govi
  • 687
  • 8
  • 21
Arpi
  • 397
  • 2
  • 5
  • 14

2 Answers2

0

When you add your images, make sure they are added with the following naming convention: myImage@2x.ext. This will clear up your fuzzy images by instructing the os to use the higher resolution image if supported. I've noticed some downsampling of images if you don't add the @2x version. You still reference your images the same way in code i.e. myImage.ext

See this Using images in iPhone (normal and @2x) for more detail

Community
  • 1
  • 1
Wizkid
  • 1,015
  • 10
  • 10
0

In my own case, I:

  1. resized each of the tab images to 64px by 64px.
  2. then moved them to Assets.xcassets in my xCode IDE.
  3. selected each image and moved it away from 1x to 2x enter image description here

Hope this helps someone!

Aweda
  • 323
  • 1
  • 4
  • 15