zoukankan      html  css  js  c++  java
  • 轻量级UIImageView分类缓存 库 AsyncImageView 使用

    轻量级UIImageView分类缓存 库 AsyncImageView 使用

    一:

    二:使用

       主要演示结合UITableview的使用

        demo代码:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            //create new cell
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            
            //common settings
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
            cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
            cell.imageView.frame = CGRectMake(0.0f, 0.0f, 44.0f, 44.0f);
            cell.imageView.clipsToBounds = YES;
        }
        else
        {
            //cancel loading previous image for cell
            [[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:cell.imageView];
        }
        
        //set placeholder image or cell won't update when image is loaded
        cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
        
        //load the image
        cell.imageView.imageURL = self.imageURLs[(NSUInteger)indexPath.row];
        
        //display image path
        cell.textLabel.text = [[(NSURL *)self.imageURLs[(NSUInteger)indexPath.row] path] lastPathComponent];
        
        return cell;
    }
    View Code

         demo 代码:

      

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        
    #define IMAGE_VIEW_TAG 99
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            //create new cell
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            
            //add AsyncImageView to cell
            AsyncImageView *imageView = [[AsyncImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 44.0f, 44.0f)];
            imageView.contentMode = UIViewContentModeScaleAspectFill;
            imageView.clipsToBounds = YES;
            imageView.tag = IMAGE_VIEW_TAG;
            [cell addSubview:imageView];
            
            //common settings
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
            cell.indentationWidth = 44.0f;
            cell.indentationLevel = 1;
        }
        
        //get image view
        AsyncImageView *imageView = (AsyncImageView *)[cell viewWithTag:IMAGE_VIEW_TAG];
        
        //cancel loading previous image for cell
        [[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:imageView];
        
        //load the image
        imageView.imageURL = [_imageURLs objectAtIndex:indexPath.row];
            
        //display image path
        cell.textLabel.text = [[[_imageURLs objectAtIndex:indexPath.row] path] lastPathComponent];
    
        return cell;
    }
    View Code

    三:可用api

      

    @interface AsyncImageLoader : NSObject
    
    + (AsyncImageLoader *)sharedLoader;
    + (NSCache *)defaultCache;
    
    @property (nonatomic, strong) NSCache *cache;
    @property (nonatomic, assign) NSUInteger concurrentLoads;
    @property (nonatomic, assign) NSTimeInterval loadingTimeout;
    
    - (void)loadImageWithURL:(NSURL *)URL target:(id)target success:(SEL)success failure:(SEL)failure;
    - (void)loadImageWithURL:(NSURL *)URL target:(id)target action:(SEL)action;
    - (void)loadImageWithURL:(NSURL *)URL;
    - (void)cancelLoadingURL:(NSURL *)URL target:(id)target action:(SEL)action;
    - (void)cancelLoadingURL:(NSURL *)URL target:(id)target;
    - (void)cancelLoadingURL:(NSURL *)URL;
    - (void)cancelLoadingImagesForTarget:(id)target action:(SEL)action;
    - (void)cancelLoadingImagesForTarget:(id)target;
    - (NSURL *)URLForTarget:(id)target action:(SEL)action;
    - (NSURL *)URLForTarget:(id)target;
    
    @end
    
    
    @interface UIImageView(AsyncImageView)
    
    @property (nonatomic, strong) NSURL *imageURL;
    
    @end
    
    
    @interface AsyncImageView : UIImageView
    
    @property (nonatomic, assign) BOOL showActivityIndicator;
    @property (nonatomic, assign) UIActivityIndicatorViewStyle activityIndicatorStyle;
    @property (nonatomic, assign) NSTimeInterval crossfadeDuration;
    
    @end
    View Code
  • 相关阅读:
    win10使用4G 模块RNDIS模式上网
    转]GSM模块信号强度CSQ与RSSI的对应关系
    /etc/inittab文件详解
    网口扫盲一:网卡初步认识
    网口扫盲二:Mac与Phy组成原理的简单分析
    网口扫盲三:以太网芯片MAC和PHY的关系
    【 MAKEFILE 编程基础之四】详解MAKEFILE 函数的语法与使用!
    【 MAKEFILE 编程基础之三】详解 MAKEFILE 变量的定义规则使用!
    转载:基于jquery的bootstrap在线文本编辑器插件Summernote
    HTML特殊符号对照表、常用的字符实体
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3611614.html
Copyright © 2011-2022 走看看