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. Python.resource-for-python-from-internet

    1. pyvideo Python related video indexed so you can find it. http://pyvideo.org/ 2. 6 Useful Python L ...

  2. 从DNS配置

    从服务器可以从主服务器上抓取指定的区域数据文件起到备份解析记录和负载均衡的作用. 主DNS服务器IP:192.168.16.20 从DNS服务器IP:192.168.16.30 1,修改主服务器区域配 ...

  3. 递推 N矩形问题

    Description 给你一个高为n ,宽为m列的网格,计算出这个网格中有多少个矩形,下图为高为2,宽为4的网格. Input 第一行输入一个t, 表示有t组数据,然后每行输入n,m,分别表示网格的 ...

  4. 传值 属性 block 单例 协议

    界面传值 四种传值的方式 1.属性传值(从前往后) 步骤: 1.属性传值用于第一个界面向第二个界面传值 2.明确二者联系的桥梁,也就是触发跳转的地方 3.明确传输的值,类型是什么 4.在第二个视图控制 ...

  5. Linux上设置nginx支持https

    1.前提条件 如果系统没有自带openssl,则需要安装. 2.生成证书 # .首先,进入你想创建证书和私钥的目录,例如: cd /etc/nginx/ # .创建服务器私钥,命令会让你输入一个口令: ...

  6. Mysql --分区表(2)

    分区类型 RANGE分区 range分区的表是利用取值范围将数据分成分区,区间要连续并且不能互相重叠,使用values less than操作符进行分区定义 LIST分区 LIST分区是建立离散的值列 ...

  7. Druid的使用步骤

    一.关于Druid Druid是一个JDBC组件,它包括三部分: DruidDriver 代理Driver,能够提供基于Filter-Chain模式的插件体系. DruidDataSource 高效可 ...

  8. 重启EBS

    http://www.cnblogs.com/toowang/archive/2012/03/28/2421275.html 概述步骤(此操作没有停止数据库): 1.登陆FTP,终止应用:cd $CO ...

  9. C#设计模式(14)——模板方法模式(Template Method)

    一.引言 提到模板,大家肯定不免想到生活中的“简历模板”.“论文模板”.“Word中模版文件”等,在现实生活中,模板的概念就是——有一个规定的格式,然后每个人都可以根据自己的需求或情况去更新它,例如简 ...

  10. JsCss笔记

    1.  &= 不应该在 Bool 型变量中使用. a &= b  对于Js来说是:  a = a & b ;  a 本来是 bool , &= 之后就变成了 Int. ...