SDWebImage

//
//  ViewController.m
//  07_07
//
//  Created by Song on 2020/7/7.
//  Copyright © 2020 Song. All rights reserved.
//

#import "ViewController.h"
#import 
#import 
#import 

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)getSize:(id)sender;
- (IBAction)clearMemory:(id)sender;
- (IBAction)loadPic:(id)sender;


@end

@implementation ViewController
// http报错不安全,不能显示
// http://f.hiphotos.baidu.com/zhidao/pic/item/a5c27d1ed21b0ef486339c21dbc451da80cb3ef1.jpg
// https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1504497742352&di=1d930dcfad527fb80f62e696e4cbd54b&imgtype=0&src=http%3A%2F%2Fpic15.nipic.com%2F20110730%2F7689559_151457143162_2.jpg
static NSString * imageURL = @"http://f.hiphotos.baidu.com/zhidao/pic/item/a5c27d1ed21b0ef486339c21dbc451da80cb3ef1.jpg";
static NSString * gifURL = @"https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1876884466,1157960341&fm=26&gp=0.jpg";

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 初始化一个view
//    UIView *bgView = [[UIView alloc] init];
//    bgView.backgroundColor = [UIColor redColor];
//    [self.view addSubview:bgView];
    // 使用mas_makeConstraints添加约束
//    [bgView mas_makeConstraints: ^(MASConstraintMaker *make) {
//        make.center.equalTo(self.view);
//        make.size.mas_equalTo(CGSizeMake(200, 200));
//    }];
    // 设置一个基于父视图间距为10的view
//    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.center.equalTo(self.view);
//        make.edges.mas_offset(UIEdgeInsetsMake(10, 10, 10, 10));
//    }];
//
    
    /*
     2个view横向居中,第二个view距离第一个view间距为10
     */
//    UIView *view1 = [[UILabel alloc] init];
//    view1.backgroundColor = [UIColor blackColor];
//    [self.view addSubview:view1];
//    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(90, 90));
//        make.centerX.equalTo(self.view);
//        make.top.width.offset(90);
//    }];
//
//    UIView *view2 = [[UILabel alloc] init];
//    view2.backgroundColor = [UIColor blueColor];
//    [self.view addSubview:view2];
//    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(100, 100));
//        make.centerX.equalTo(view1);
//        make.top.equalTo(view1.mas_bottom).with.offset(20);
//    }];
    
}




- (IBAction)clearMemory:(id)sender {
    /*
     异步清除所有磁盘缓存映像。非阻塞方法-立即返回。@param完成一个应该在缓存过期后执行的块(可选)
     
     注意:这里要注意[[SDImageCache sharedImageCache] clearDisk];方法会报错,下面clearDiskOnCompletion的方法会替代上面的方法
     */
    [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
        
    }];
    
    /*
     Clear all memory cached images --->清除所有缓存镜像
     */
    [[SDImageCache sharedImageCache] clearMemory];
    
    /*
     异步将所有过期的缓存映像从磁盘中删除。非阻塞方法-立即返回。@param completionBlock在缓存过期后执行(可选)--->故名思义他是不能删除你当前缓存的大小的
     */
    [[SDImageCache sharedImageCache] deleteOldFilesWithCompletionBlock:^{
        
    }];
}

- (IBAction)getSize:(id)sender {
    //之前的getSize变成了totalDiskSize
    CGFloat size = [[SDImageCache sharedImageCache] totalDiskSize];
    NSLog(@"%f", size);
}



- (IBAction)loadPic:(id)sender {
    // 可以加载gif和其他的
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:gifURL] placeholderImage:[UIImage imageNamed:@"song"]];
}


@end

你可能感兴趣的:(SDWebImage)