How does iOS cache images and iOS images?
How does iOS cache images?
In iOS development, it is common to get images from the network. If we load a lot of images, we should add cache to the images so that the next time we can quickly read the images, improve Efficiency
Note: Only one view is created, and no other attributes are written.
1. Normal image loading method (no cache ):
UIImageView * imageView = [[UIImageView alloc]init]; imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png"]]];
2. You can use a third-party library SDWebImage to add a cache for images.
Download the latest SDWebImage and drag them to the project to import # import "UIImageView + WebCache. h "is introduced into the project. The following example adds a cache to the image. The first time the cache is slow, it will soon become available.
[imageView setImageWithURL:[NSURL URLWithString:@"http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png"] placeholderImage:[UIImage imageNamed:@"1.png"]];
PlaceholderImage: [UIImage imageNamed: @ "1.png"]. Here is a backup image that has not been loaded.