SDWebImage的一些小东西

来源:互联网 发布:2017最新网络热门话题 编辑:程序博客网 时间:2024/05/22 00:50

1.清理SD图片缓存

    a.一般我会写上以下两句,如果你只写上面一句也是没有问题的(根据大神杨的提醒,已改成三句)

   [[SDImageCache sharedImageCache] clearDisk];

   [[SDImageCache sharedImageCache] cleanDisk];

   上面两句全是把之前调用的block置为nil;

   [[SDImageCachesharedImageCache]clearMemory];


2.添加图片3种方式

    a.常用的加载方式     

    [image sd_setImageWithURL:[NSURLURLWithString:@“图片地址”]placeholderImage:@"缺省页"];

  

    b.增加一个完成后的回调方法---- 当加载图片处理完后回调一个block(可以判断时候正常加载成功)

     [image sd_setImageWithURL:[NSURL URLWithString:@"图片地址"] placeholderImage:@"缺省页"completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

       //完成时的操作

    }];


    c.增加一个判断 

    因为正常如果sd加载图片加载的图片失败了,因为缓存机制下次刷新是不会加载的,这样图片会一直不去刷新显示错误的图片,这个参数就是为了解决这个问题,如果图片失败了下次已然会重新加载。

     [image sd_setImageWithURL:[NSURL URLWithString:@"图片地址"] placeholderImage:@"缺省页" options:SDWebImageRetryFailed];


   d.加载图片后不缓存在本地

   把options中的参数设置成SDWebImageRefreshCached。

     [image sd_setImageWithURL:[NSURL URLWithString:@"图片地址"] placeholderImage:@"缺省页"options:SDWebImageRefreshCached];




如果你有更好的小窍门欢迎留言哦~

感谢观看学以致用更感谢!




0 0
原创粉丝点击