iOS 網路圖片大小自適應
基於SDWebImage實現:
__weak typeof(self)weakSelf = self;
[self.imageView sd_setImageWithURL:[NSURL URLWithString:gM1.imageUrl] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
CGSize size = image.size;
weakSelf.imageView.heightJT = RECTWIDTH*size.height/size.width;
}];
防止記憶體溢位:
1、新增#import "SDImageCache.h"標頭檔案
在使用SDWebImage載入較多圖片造成記憶體警告時,定期呼叫
[[SDImageCache sharedImageCache] setValue:nil forKey:@“memCache”];
2、在AppDelegate.m檔案
-(void)applicationDidReceiveMemoryWarning:(UIApplication *)application{
// 取消正在下載的操作
[[SDImageCache sharedImageCache] cancelAll];
// 清除記憶體快取
[[SDImageCache sharedImageCache] clearDiskOnCompletion:nil]; [[SDImageCache sharedImageCache] clearMemory];
}
擴充套件:
https://blog.csdn.net/benyoulai5/article/details/50462586
擴充套件 AppDelegate.m 方法:
https://www.jianshu.com/p/14118d40a878
https://www.cnblogs.com/tongyuling/p/4648976.html