【问题标题】:TabBar item Images blur in retina displayTabBar 项目图像在视网膜显示中模糊
【发布时间】:2014-07-15 12:53:00
【问题描述】:

我在使用 Tabbar Controller 时遇到问题,即标签栏项目的图像在视网膜 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 像素。现在我没有得到导致图像模糊的原因。帮我解决这个问题。

【问题讨论】:

    标签: ios retina-display uitabbaritem


    【解决方案1】:

    添加图像时,请确保使用以下命名约定添加它们:myImage@2x.ext。如果支持,这将通过指示操作系统使用更高分辨率的图像来清除您的模糊图像。如果您不添加 @2x 版本,我会注意到一些图像的下采样。您仍然在代码中以相同的方式引用您的图像,即 myImage.ext

    查看Using images in iPhone (normal and @2x)了解更多详情

    【讨论】:

      【解决方案2】:

      就我自己而言,我:

      1. 将每个标签图像的大小调整为 64 x 64 像素。
      2. 然后将它们移至我的 xCode IDE 中的 Assets.xcassets。
      3. 选择每个图像并将其从 1x 移到 2x

      希望这对某人有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多