我遇到Tabbar控制器的问题,标签栏项目的图像在视网膜iOS设备中模糊。这是我在标签栏项目中的图像代码如下:
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];
}
所有图像的尺寸均为96X80像素。现在我没有得到导致模糊图像的原因。帮我解决这个问题。
答案 0 :(得分:0)
添加图像时,请确保使用以下命名约定添加它们:myImage@2x.ext。这将通过指示操作系统使用更高分辨率的图像(如果支持)来清除模糊图像。如果你不添加@ 2x版本,我注意到了一些图像的下采样。你仍然在代码中以相同的方式引用你的图像,即myImage.ext
有关详细信息,请参阅此Using images in iPhone (normal and @2x)
答案 1 :(得分:0)