简体   繁体   English

使用缓存中的图像设置UIImageView

[英]Setting UIImageView with image from cache

I cache an image when the user logs in like this: 当用户这样登录时,我缓存图像:
This is in a Utility.m 这是在Utility.m

UIImage *image = [UIImage imageWithData:newProfilePictureData];

UIImage *mediumImage = [image thumbnailImage:280 transparentBorder:0 cornerRadius:0 interpolationQuality:kCGInterpolationHigh];
UIImage *smallRoundedImage = [image thumbnailImage:64 transparentBorder:0 cornerRadius:9 interpolationQuality:kCGInterpolationLow];

NSData *mediumImageData = UIImageJPEGRepresentation(mediumImage, 0.5); // using JPEG for larger pictures
NSData *smallRoundedImageData = UIImagePNGRepresentation(smallRoundedImage);

Later on I would like to load the small image into an UIImageView : 稍后,我想将小图像加载到UIImageView
This is in a UITableView - cellForRowAtIndexPath 这在UITableView cellForRowAtIndexPath

[cell.leftIcon setImage:

Does anyone know how I can reference the cached image? 有谁知道我如何引用缓存的图像?

You need something like below method in Utility.m, 您需要在Utility.m中使用以下方法,

+(NSString*)getImage {
    return smallRoundedImage;
}

Then use it like below, 然后像下面一样使用它,

[cell.leftIcon setImage:[Utility getImage]];

PS: This is just an example, you can make this much better based on what's your requirements! PS:这只是一个例子,您可以根据自己的要求将其做得更好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM