PlaceholderImageView

说明

1. PlaceHolderImageView基于SDWebImage编写

2. 给定一个图片的urlString,以及一个placeholderImage就可以优雅的显示图片加载效果

效果

源码

PlaceholderImageView.h/.m
//
// PlaceholderImageView.h
// SDWebImageViewPlaceHorder
//
// Created by YouXianMing on 16/9/14.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface PlaceholderImageView : UIView /**
* Picture's url string.
*/
@property (nonatomic, strong) NSString *urlString; /**
* The placeholder's image.
*/
@property (nonatomic, strong) UIImage *placeholderImage; /**
* Default is UIViewContentModeScaleAspectFill.
*/
@property (nonatomic) UIViewContentMode placeholderImageContentMode; /**
* Default is UIViewContentModeScaleAspectFill.
*/
@property (nonatomic) UIViewContentMode contentImageContentMode; @end
ImageCell.h/.m
//
// ImageCell.h
// SDWebImageViewPlaceHorder
//
// Created by YouXianMing on 16/9/14.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h>
#import "PlaceholderImageView.h" @interface ImageCell : UITableViewCell @property (nonatomic, strong) PlaceholderImageView *placeholderImageView; @end
//
// ImageCell.m
// SDWebImageViewPlaceHorder
//
// Created by YouXianMing on 16/9/14.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "ImageCell.h" @implementation ImageCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.placeholderImageView = [[PlaceholderImageView alloc] initWithFrame:CGRectMake(, , .f, .f)];
self.placeholderImageView.placeholderImage = [UIImage imageNamed:@""];
[self addSubview:self.placeholderImageView];
} return self;
} @end
ViewController.m
//
// ViewController.m
// SDWebImageViewPlaceHorder
//
// Created by YouXianMing on 16/9/14.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "ViewController.h"
#import "UIImageView+WebCache.h"
#import "PlaceholderImageView.h"
#import "ImageCell.h" @interface ViewController () <UITableViewDelegate, UITableViewDataSource> @property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *pictures; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.pictures = @[@"https://pic.cnblogs.com/avatar/607542/20151017230728.png",
@"https://pic.cnblogs.com/face/607741/20140226202001.png",
@"https://pic.cnblogs.com/face/815231/20150923160245.png",
@"https://pic.cnblogs.com/face/993558/20160729092113.png",
@"https://pic.cnblogs.com/face/894202/20160217151952.png",
@"https://pic.cnblogs.com/face/968459/20160709111712.png",
@"https://pic.cnblogs.com/face/145865/20160210174306.png",
@"https://pic.cnblogs.com/face/796658/20151026090914.png",
@"https://pic.cnblogs.com/face/933887/20160629214007.png",
@"https://pic.cnblogs.com/face/125303/20130313094252.png",
@"https://pic.cnblogs.com/face/976232/20160730173456.png",
@"https://pic.cnblogs.com/face/969708/20160602120239.png",
@"https://pic.cnblogs.com/face/954541/20160705113740.png",
@"https://pic.cnblogs.com/face/799942/20150818204115.png"]; PlaceholderImageView *pImageView = [[PlaceholderImageView alloc] initWithFrame:CGRectMake(, , .f, .f)];
[self.view addSubview:pImageView];
pImageView.urlString = @"https://pic.cnblogs.com/avatar/607542/20151017230728.png"; self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.rowHeight = .f;
[self.view addSubview:self.tableView]; [self.tableView registerClass:[ImageCell class] forCellReuseIdentifier:@"ImageCell"];
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _pictures.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ImageCell"];
cell.placeholderImageView.urlString = _pictures[indexPath.row]; return cell;
} @end

PlaceholderImageView的更多相关文章

  1. 用SDWebImage渐变加载图片

    用SDWebImage渐变加载图片 使用 使用请详细查看源码,只需要给定一个图片地址以及一个placeHolder图片(非必须)即可. 效果 源码 https://github.com/YouXian ...

随机推荐

  1. 抓包工具Charles,anyproxy,mitmproxy等

    Charles:图形化界面,看着比较方便友好,也可以抓取https,不过电脑和手机都要下载证书,主要我的电脑上不能添加一添加就卡死 所以,抓取https的话,就用mitmproxy比较简单 1.安装C ...

  2. 【转】supervisor安装与配置

    1.安装 宿主机环境:(Centos7) 宿主机环境 #yum install python-setuptools yum install python-setuptools#easy_install ...

  3. SQL语句一次INSERT多条记录的方法

    1.SQL Server或MySQL中: INSERT INTO `userTable` (`user_id`, `user_name`) VALUES (, 'dsf'), (, 'fgy'), ( ...

  4. XproerIM产品使用手册

      1.  产品介绍 版权所有:(c)2009-2016 荆门泽优软件有限公司 保留所有权利. 产品官网:http://www.ncmem.com/apps/xproerim/index.asp 安装 ...

  5. App技术框架

    一.App技术框架的类型 图1 三种App技术框架之间的关系 目前App的技术框架基本分为三种(图1): (1)Native App:互动型,iOS.Android.WP各一套,而且要维护历史版本,要 ...

  6. 精确运算--BigDecimal

    工具类 ,直接就可以使用,对于float和double的进行加减乘除长生的误差的解决办法. import java.math.BigDecimal; public class Arith { // 默 ...

  7. Incompatible operand types DeptE and int 异常处理

    Incompatible operand types DeptE and int 1.java不会运算到==的值,把==改为equals 2.java不会运算到eequals的值 把equals的改为 ...

  8. 【Leetcode】【Medium】Set Matrix Zeroes

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 解题思路: ...

  9. 使用 New Relic 监控接口服务性能

    偶然看到贴子在使用[Rails API] 使用这个APM监控,今天试了下.NET IIS环境下,配置一路NEXT即可. 主要指标 服务响应时间 Segment SQL执行时间 安全问题 1.走HTTP ...

  10. [转]一个文件上传的jquery插件

    http://www.jb51.net/article/51547.htm 这篇文章主要介绍了使用ajaxfileupload.js实现ajax上传文件php版,需要的朋友可以参考下     无论是P ...