afnetwork 使用

第三方库SDWebImage的使用(附Demo)

2018-10-26  本文已影响0人  cocoaCoffee

首先将SDWebImage导入项目

使用CocoaPads安装第三方库

platform :ios, '8.0'

target ‘图片缓存练习’ do
  pod 'SDWebImage'   
end 
//库名后不加版本,默认最新版本

流程

盗图

主要方法:

加载图片的方法在pods的UIImageView+WebCache类中

UIImageView+WebCache

说一下前几种

1.没有有占位图的加载方式

- (void)sd_setImageWithURL:(nullable NSURL *)url

2.有占位图的加载方式

////给一张默认图片,先使用默认图片,当图片加载完成后再替换,占位符的名字随你定
- (void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder

3.没占位图的加载方式 并且实现回调Block完成下一步任务

- (void)sd_setImageWithURL:(nullable NSURL *)url completed:(nullable SDExternalCompletionBlock)completedBlock

4.使用可更换optionsType的加载方式

-(void)sd_setImageWithURL:(nullable NSURL *)url placeholderImage:(nullable UIImage *)placeholder options:(SDWebImageOptions)options

Options 枚举如下:

(以上均为复制粘贴)

图片缓存


注意:最重要的来了

解决方法:在Info.plist中添加NSAppTransportSecurity类型Dictionary。
在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES。


image.png

Demo地址

上一篇 下一篇

猜你喜欢

热点阅读