项目中从服务器端下载图片这些几乎是必备的,使用时也很简单,只需引入SDWebImage文件

//
//  ViewController.m
//  sdWebImageDemo
//
//  Created by City--Online on 15/6/15.
//  Copyright (c) 2015年 City--Online. All rights reserved.
//

#import "ViewController.h"
#import "UIImageView+WebCache.h"

@interface ViewController ()
@property(nonatomic,strong) UIImageView *imgView1;
@property(nonatomic,strong) UIImageView *imgView2;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *claerBtn=[UIButton buttonWithType:UIButtonTypeSystem];
    [claerBtn setTitle:@"清除缓存" forState:UIControlStateNormal];
    claerBtn.frame=CGRectMake(, , , );
    [claerBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    claerBtn.tag=;
    [self.view addSubview:claerBtn];

    UIButton *loadBtn=[UIButton buttonWithType:UIButtonTypeSystem];
    [loadBtn setTitle:@"加载" forState:UIControlStateNormal];
    loadBtn.frame=CGRectMake(, , , );
    [loadBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    loadBtn.tag=;
    [self.view addSubview:loadBtn];

    _imgView1=[[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
    _imgView1.backgroundColor=[UIColor grayColor];
    [self.view addSubview:_imgView1];

    _imgView2=[[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
    _imgView2.backgroundColor=[UIColor grayColor];
    [self.view addSubview:_imgView2];

}
-(void)btnClick:(id)sender
{
    UIButton *btn=(UIButton *)sender;
    ) {
        [[SDImageCache sharedImageCache] clearDisk];

        [[SDImageCache sharedImageCache] clearMemory];
    }
    )
    {
        NSURL *imgPath1=[NSURL URLWithString:@"http://s15.sinaimg.cn/middle/9914f9fdhbc6170891ebe&690"];
        NSURL *imgPath2=[NSURL URLWithString:@"http://s14.sinaimg.cn/middle/9914f9fdhbc611c219f3d&690"];

        //基本使用方法
//        [_imgView1 sd_setImageWithURL:imgPath1 ];
//
//        //block
//        [_imgView2 sd_setImageWithURL:imgPath2 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//            NSLog(@"这里可以在图片加载完成之后做些事情");
//        }];

        //预先设定一张图片
//        [_imgView1 sd_setImageWithURL:imgPath1 placeholderImage:[UIImage imageNamed:@"default.jpg"]];
//
//        //block 预先设定一张图片
//        [_imgView2 sd_setImageWithURL:imgPath2 placeholderImage:[UIImage imageNamed:@"default.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//            NSLog(@"这里可以在图片加载完成之后做些事情");
//        }];
//
        [_imgView1 sd_setImageWithURL:imgPath1 placeholderImage:[UIImage imageNamed:@"default.jpg"] options:SDWebImageCacheMemoryOnly];

        SDWebImageManager *manager=[SDWebImageManager sharedManager];
        [manager downloadImageWithURL:imgPath2 options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) {
            NSLog(@"%f",receivedSize/(float)expectedSize);

        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
            NSLog(@"下载完成");
            _imgView2.image=image;
        }];
//

        //    /*
        //     //失败后重试
        //     SDWebImageRetryFailed = 1 << 0,
        //
        //     //UI交互期间开始下载,导致延迟下载比如UIScrollView减速。
        //     SDWebImageLowPriority = 1 << 1,
        //
        //     //只进行内存缓存
        //     SDWebImageCacheMemoryOnly = 1 << 2,
        //
        //     //这个标志可以渐进式下载,显示的图像是逐步在下载
        //     SDWebImageProgressiveDownload = 1 << 3,
        //
        //     //刷新缓存
        //     SDWebImageRefreshCached = 1 << 4,
        //
        //     //后台下载
        //     SDWebImageContinueInBackground = 1 << 5,
        //
        //     //NSMutableURLRequest.HTTPShouldHandleCookies = YES;
        //
        //     SDWebImageHandleCookies = 1 << 6,
        //
        //     //允许使用无效的SSL证书
        //     //SDWebImageAllowInvalidSSLCertificates = 1 << 7,
        //
        //     //优先下载
        //     SDWebImageHighPriority = 1 << 8,
        //
        //     //延迟占位符
        //     SDWebImageDelayPlaceholder = 1 << 9,
        //
        //     //改变动画形象
        //     SDWebImageTransformAnimatedImage = 1 << 10,
        //     */
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

IOS第三方之SDWebImage的更多相关文章

  1. iOS 第三方框架-SDWebImage

    iOS中著名的牛逼的网络图片处理框架.包含的功能:图片下载.图片缓存.下载进度监听.gif处理等等.用法极其简单,功能十分强大,大大提高了网络图片的处理效率.国内超过90%的iOS项目都有它的影子. ...

  2. iOS 第三方库、插件、知名博客总结

    iOS 第三方库.插件.知名博客总结 用到的组件 1.通过CocoaPods安装 项目名称 项目信息 AFNetworking 网络请求组件 FMDB 本地数据库组件 SDWebImage 多个缩略图 ...

  3. 超全!整理常用的iOS第三方资源(转)

    超全!整理常用的iOS第三方资源 一:第三方插件 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地 ...

  4. ios开发清除SDWebImage图片缓存

    一:一般在实际的项目应用中都会用到第三方框架SDWebImage去下载缓存图片,但在ios开发应用中,常常涉及对SDWebImage缓存图片的清除.本文所列出代码即是对SDWebImage缓存图片的清 ...

  5. iOS第三方库管理工具

    作者:彷徨iOS 原文地址1:http://iostree.sinaapp.com/?p=78 原文地址2:http://blog.csdn.net/wzzvictory/article/detail ...

  6. fir.im Weekly - 热门 iOS 第三方库大盘点

    本期 fir.im Weekly 收集的热度资源,大部分关于Android.iOS 开发工具.源码和脑洞大开的 UI 动画,希望给你带来更多的工作创意与灵感. 盘点国内程序员不常用的热门iOS第三方库 ...

  7. ios 第三方登录

    ios 第三方登录通常的做法是, 1.登录后,获得第三方的uid,调用服务器登录接口,如服务器返回无此用户,转2,有此用户,转3. 2.服务器返回无此用户,需完善用户资料,如果完成,则在服务器创建与第 ...

  8. 你一定能用的上的iOS第三方库

    点国内程序员不常用的热门iOS第三方库:看完,还敢自称"精通iOS开发"吗? 综合github上各个项目的关注度与具体使用情况,涵盖功能,UI,数据库,自动化测试,编程工具等类型, ...

  9. iOS第三方库

    热门iOS第三方库:看完,还敢自称”精通iOS开发”吗? 综合github上各个项目的关注度与具体使用情况,涵盖功能,UI,数据库,自动化测试,编程工具等类型,看完,还敢自称”精通iOS开发”吗? h ...

随机推荐

  1. FreeBSD下面安装PostgreSQL。

    1.确认pkg版本大于1.1.4,可以用pkg -v查看,如果小于此版本,请升级.2.在/usr/local/etc/pkg.conf文件中,删除掉repository相关的语句,像PACKAGESI ...

  2. 在AbpZero中hangfire后台作业的使用——hangfire的调度

    在abpzero框架中,hangfiire通过依赖注入来进行接口的调用 hangfire的事件处理分为以下几种: 1.基于队列的任务处理(Fire-and-forget jobs) var jobId ...

  3. wpf简单进度条

    UserControl x:Class="WpfApplication1.UserControl2" xmlns="http://schemas.microsoft.co ...

  4. Win(Phone)10开发第(5)弹,本地媒体服务器的一些注意事项

    首先有个wp上的http服务器 http://wphttpserver.codeplex.com/ 使用方式: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

  5. C# VS .NET 版本对应关系

    ╔══════╦══════╦═══════╦════ ══╦═══════╗ ║ C# version ║ VS version ║ .NET version ║ CLR version ║ Rel ...

  6. Spring boot创建定时任务

    基于spring boot的应用创建定时任务不要太简单,给一个类加上@Configuration @EnableScheduling注解,然后给该类需要定时执行的方法加上@Scheduled(cron ...

  7. win10中shift+右键,在此处打开cmd窗口

    通过添加注册表项,实现右击“在此处打开命令行功能” 注册表位置:HKEY_CLASSES_ROOT\Directory\Background\shell\ win10系统用标识右键菜单打开命令行的键, ...

  8. Atcoder Tenka1 Programmer Contest 2019题解

    传送门 \(C\ Stones\) 最后肯定形如左边一段白+右边一段黑,枚举一下中间的断点,预处理一下前缀和就可以了 int main(){ // freopen("testdata.in& ...

  9. APP间传递消息

    https://www.jianshu.com/p/d640ccfcea5f 1: URL Scheme 常用的App间传值方式.常见于分享等. 2: Keychain  借助系统类 Keychain ...

  10. Python拾遗

    for...else...语句 用 break 关键字终止当前循环就不会执行当前的 else 语句,而使用 continue 关键字快速进入下一论循环,或者没有使用其他关键字,循环的正常结束后,就会触 ...