项目中从服务器端下载图片这些几乎是必备的,使用时也很简单,只需引入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. kylin的配置账号密码的加密方法

    kylin的配置账号密码的加密方法 kylin安装过程中,配置账户,其中密码是加密的.生成密码对应密文的 方法如下: import java.io.PrintStream; import org.sp ...

  2. WorkSpace

    --往GridControl中添加绑定数据 // 房间费用 DataTable dtRoomInfo = new DataTable(); dtRoomInfo.Columns.Add("v ...

  3. sql service 备份

    declare @SqlBackupDataBase as nvarchar(1000)set @SqlBackupDataBase=N'BACKUP DATABASE YSKJ_Wechat TO ...

  4. A tiny program to benchmark image transpose algorithms

    Here is the code: #include <stdio.h> #include <xmmintrin.h> #include <windows.h> t ...

  5. day72 Ajax 第一天

    第一个示例:(i1+i2 ) 前端数据 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  6. FTP 作业整理

    一.FTP 客户端 与服务器端(没有解决黏包问题的代码) 服务器端设置 import socket import json ADDR = () sk =socket.socket() sk.bind( ...

  7. C++单继承的构造函数和析构函数调用的顺序

    1.继承构造函数调用顺序以及销毁的过程 先调用父类的构造函数,在调用子类的构造函数,析构函数调用相反.

  8. php判断是否使用手机访问

    直接上代码 /** * 检测是否使用手机访问 * @access public * @return bool */ public function isMobile() { if (isset($_S ...

  9. 【转载】 C#中数组、ArrayList和List三者的区别

    原文地址:http://blog.csdn.net/zhang_xinxiu/article/details/8657431 在C#中数组,ArrayList,List都能够存储一组对象,那么这三者到 ...

  10. SAS->关联分析实践

    SAS系统被誉为国际上的标准软件系统,本文将详细介绍如何在SAS/EM模块中进行关联规则数据挖掘,使用的软件版本是SAS 9.1.3下的Enterprise Miner 4.3: 从SAS顶端的[解决 ...