本文介绍了imageNamed是邪恶的-如何使用该功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- (UIImage*)thumbnailImage:(NSString*)fileName
{
UIImage *thumbnail = [thumbnailCache objectForKey:fileName];
if (nil == thumbnail)
{
NSString *thumbnailFile = [NSString stringWithFormat:@"%@/thumbnails/%@.jpg", [[NSBundle mainBundle] resourcePath], fileName];
thumbnail = [UIImage imageWithContentsOfFile:thumbnailFile];
[thumbnailCache setObject:thumbnail forKey:fileName];
}
return thumbnail;
}
我从 http://www获得了此代码.alexcurylo.com/blog/2009/01/13/imagenamed-is-evil/.有人可以告诉我如何使用此代码.我只需要一点帮助,即可代替imageNamed来使用它.
I got this code from http://www.alexcurylo.com/blog/2009/01/13/imagenamed-is-evil/ . Can someone tell me how to use this code. I need just a little help how to use this in place of imageNamed.
推荐答案
NSMutableDictionary *thumbnailCache=[[NSMutableDictionary alloc]init];
然后将"thumbnails"文件夹添加到您的资源文件夹中,然后将ur png放在此处
then add "thumbnails" folder to ur resource folder then put ur png there
- (UIImage*)thumbnailImage:(NSString*)fileName
{
UIImage *thumbnail = [thumbnailCache objectForKey:fileName];
if (nil == thumbnail)
{
NSString *thumbnailFile = [NSString stringWithFormat:@"%@/thumbnails/%@.jpg", [[NSBundle mainBundle] resourcePath], fileName];
thumbnail = [UIImage imageWithContentsOfFile:thumbnailFile];
[thumbnailCache setObject:thumbnail forKey:fileName];
}
return thumbnail;
}
示例
将foo.png添加到资源文件夹//然后在此处创建UIImageView对象
add foo.png to resource folder//here create UIImageView object then
UIImageviewObject.image=[self thumbnailImage:@"foo.png"];
这篇关于imageNamed是邪恶的-如何使用该功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!