设为首页 加入收藏

TOP

iOS 用 SDWebImage 清理图片缓存(一)
2017-10-13 10:17:12 】 浏览:587
Tags:iOS SDWebImage 清理 图片

效果图如下:

 

1.找到 SDWebImage找到SDImageCache类

2.添加如下方法

- (float)checkTmpSize
{
    float totalSize = 0;
    NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:_diskCachePath];
    for (NSString *fileName in fileEnumerator)
    {
        NSString *filePath = [_diskCachePath stringByAppendingPathComponent:fileName];
        
        NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
        
        unsigned long long length = [attrs fileSize];
        
        totalSize += length / 1024.0 / 1024.0;
    }
    //    NSLog(@"tmp size is %.2f",totalSize);
    
    return totalSize;
}

 

具体用tableView实现

MoreViewController.h

#import "BaseViewController.h"
#import "More.h"
@interface MoreViewController : BaseViewController<UITableViewDataSource,UITableViewDelegate>

@property(strong,nonatomic)UITableView *MoreTableView;
@property(strong,nonatomic)NSArray *arrayTitle;
@property(strong,nonatomic)NSArray *arrayImage;

@end

 

MoreViewController.m 

#import "MoreViewController.h"

@interface MoreViewController ()
@property(strong,nonatomic)UILabel *lbl;
@end

@implementation MoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"更多";
    [self _loadData];
    NSLog(@"%@",NSHomeDirectory());
}

-(void)_loadData
{
    // 设置tableview的title和image
    self.arrayTitle=@[@"清除缓存",@"给个评价",@"商务合作",@"检测行版本",@"欢迎页",@"关于"];
    self.arrayImage=@[@"moreClear@2x",@"moreScore@2x",@"moreBusiness@2x",@"moreVersion@2x",@"moreWelcome@2x",@"moreAbout@2x"];
    // 初始化UItableView
    self.MoreTableView=[[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    // 设置UItableView的背景色
    self.MoreTableView.backgroundColor=[UIColor blackColor];
    // 指定代理
    self.MoreTableView.delegate=self;
    self.MoreTableView.dataSource=self;
    // 分割线的样式
    self.MoreTableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    [self.view addSubview:self.MoreTableView];
    // 指定唯一标识符
    [self.MoreTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"MoreTableCell"];
    self.lbl=[[UILabel alloc]init];
    self.lbl.textColor=[UIColor whiteColor];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arrayTitle.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MoreTableCell" forIndexPath:indexPath];
    if (indexPath.row==0) {
       self.lbl.frame= CGRectMake(200,20,200, cell.frame.size.height*0.5);
        self.lbl.text=[NSString stringWithFormat:@"缓存为%.2fMB",[[SDImageCache sharedImageCache] checkTmpSize]];
        [cell addSubview:self.lbl];
    }

    // 设置Cell的背景色
    cell.backgroundColor=[UIColor blackColor];
    // 设置title的文字颜色
    cell.textLabel.textColor=[UI
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇关于OC中直接打印结构体,点(CGRec.. 下一篇RunTime的简单使用

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目