项目中从服务器端下载图片这些几乎是必备的,使用时也很简单,只需引入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. Azure认知服务的实际应用-资讯采集推送

    Azure认知服务的实际应用-资讯采集推送 演示 实现的是通过使用各种azure服务,每天自动获取资讯.博客,定时推送到公众号的功能! 微信公众号搜索TechViews,或直接扫描二维码关注,每天推送 ...

  2. DevExpress WinForms Controls 学习系列1

    一个偶然的机会,接触到DevExpress.项目是WinForm的,应用了DevExpress.为了使项目具备维护开发的生命力,我觉得有必要系统的学习一下DevExpress,今天是学习笔记的第一篇. ...

  3. 【cocos2d-x 手游研发----怪物智能AI】

    原创文章,转载请注明出处:http://www.cnblogs.com/zisou/p/cocos2d-xARPG4.html 谈到怪物AI,我觉得就比较话多了,首先理解一下(Artificial I ...

  4. 第五章 ReentrantLock源码解析1--获得非公平锁与公平锁lock()

    最常用的方式: int a = 12; //注意:通常情况下,这个会设置成一个类变量,比如说Segement中的段锁与copyOnWriteArrayList中的全局锁 final Reentrant ...

  5. Backtracking-401. Binary Watch

    A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom ...

  6. D04——C语言基础学PYTHON

    C语言基础学习PYTHON——基础学习D04         20180810内容纲要: 1 内置函数 2 装饰器 3 生成器 4 迭代器 5 软件目录结构规范 6 小结 1 内置函数 内置函数方法详 ...

  7. MySQL多源复制(八)

    一.什么是多源复制 MySQL 5.7发布后,在复制方面有了很大的改进和提升.比如开始支持多源复制(multi-source)以及真正的支持多线程复制了.多源复制可以使用基于二进制日志的复制或者基于事 ...

  8. 在MVC过滤器中获取触发的Controller、Action、参数 等

    首先是实现接口System.Web.Mvc.IActionFilter的过滤器 获取Controller.Action.参数 方法一. string actionName = filterContex ...

  9. oracle_jdbc_insert_into

    package com.ayang.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.S ...

  10. 【java排序】 归并排序算法、堆排序算法

    一.归并排序算法 基本思想: 归并(Merge)排序法是将两个(或两个以上)有序表合并成一个新的有序表,即把待排序序列分为若干个子序列,每个子序列是有序的.然后再把有序子序列合并为整体有序序列. 归并 ...