PlaceholderImageView
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的更多相关文章
- 用SDWebImage渐变加载图片
用SDWebImage渐变加载图片 使用 使用请详细查看源码,只需要给定一个图片地址以及一个placeHolder图片(非必须)即可. 效果 源码 https://github.com/YouXian ...
随机推荐
- MySQL的binlog数据如何查看
binlog介绍 binlog,即二进制日志,它记录了数据库上的所有改变. 改变数据库的SQL语句执行结束时,将在binlog的末尾写入一条记录,同时通知语句解析器,语句执行完毕. binlog格式 ...
- dede channelartlist 中引用channel 并且设置当前选择类的样式,currentstyle暂时没有效果.特发求助!!!!
在dede中需要达到当前选择了该类,样式不同的话.如果是channelartlist 的话. 可以使用下面的情况: {dede:channelartlist typeid='6' row='3' cu ...
- Git常用命令(自己总是忘记,整理在这里)
1.git init 初始化一个空的git仓库 2.git clone +SSH地址 clone新的项目到本地 3.git add git add file 4.git commi ...
- iptables文件
# Firewall configuration written by system-config-firewall# Manual customization of this file is not ...
- Points on cycle
Description There is a cycle with its center on the origin. Now give you a point on the cycle, you a ...
- [Chapter 3 Process]Practice 3.9 Describe the actions token by a kernel to content-switch between processes.
3.9 Describe the actions token by a kernel to content-switch between processes. 答案: 内核在进行进程上下文切换时, 首 ...
- ansible 控制windows
1.installing on the control machine On a Linux control machine: #pip install "pywinrm>=0.1.1 ...
- spring常见异常
1.ClassNotFoundException: org.springframework.dao.support.DaoSupport(解决:导入spring-tx) 2.NoClassDefFou ...
- UIPageControl页控制器
一.基本知识 #import "ViewController.h"@interface ViewController ()<UIScrollViewDelegate>{ ...
- bzoj 1977
题意:求严格的次小生成树.点n<=100000,m<=300000 思路:很容易想到先做一边最小生成树,然后枚举每条非树边(u, v, w),然后其实就是把u,v路径上小于w的最大边替换成 ...