动态加载视网膜图像到标签栏
我在标签栏中使用的图像是动态的,我从互联网上加载它们。我检测我是否在视网膜显示屏上,并下载正确的图像并使用它们初始化选项卡栏。
正常图像工作正常。我的问题是视网膜图像。它们以大尺寸显示,比选项卡栏大,因此它们没有完全显示。
我想知道如何将视网膜图像加载到选项卡栏中并使它们看起来正常。
更新:
这是我用来从添加的每个视图控制器将图像加载到选项卡栏的代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithString:@"1.png"]];
UIImage* image = [UIImage imageWithContentsOfFile:path];
图像是否有 @2x 并不重要,因为我选择正常或视网膜手动图像。
The images I'm using in the tabbar are dynamic and I load them off the internet. I detect if I'm on retina display or not and download the correct images and initialize the tabbar using them.
Normal images are working fine. My problem is with retina images. They are displayed in big size, bigger than the tabbar, so they are not completely shown.
I wonder how should I load retina images into the tabbar and make them look normal.
Update:
Here's the code I'm using to load the images to the tabbar from each view controller added:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithString:@"1.png"]];
UIImage* image = [UIImage imageWithContentsOfFile:path];
It doesn't matter if the images have @2x or not as I'm choosing normal or retina images manually.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己没有遇到过这个问题,但我会在创建图像后立即设置一个断点。使用调试器检查新图像的
scale
属性。我想您会发现scale
设置为 1.0,但您的高分辨率图像应将scale
设置为 2.0。据我所知,有三种方法可以实现这一点:-initWithCGImage:scale:orientation:
或+imageWithCGImage:scale:orientation:
创建图像I haven't run across this problem myself, but I'd start by setting a breakpoint just after you create the image. Use the debugger to check the new image's
scale
property. I think you'll find thatscale
is set to 1.0, but your high resolution images should havescale
set to 2.0. There are three ways (that I know of) to make that happen:-initWithCGImage:scale:orientation:
or+imageWithCGImage:scale:orientation: