IOS program Development using Placeholderimageview to achieve elegant picture loading effect _ios

Source: Internet
Author: User
Tags reserved uikit

Description

1. Placeholderimageview based on Sdwebimage

2. Given a picture of the urlstring, and a placeholderimage can be elegant display picture loading effect

Effect

Source

Placeholderimageview.h/.m


//PlaceholderImageView.h
//Sdwebimageviewplacehorder////
Created by
youxianming on 16/9/14.
COPYRIGHT©2016 year 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 year 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 year 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 (0, 0, 150.F, 150.F)];
Self.placeholderImageView.placeholderImage = [UIImage imagenamed:@ "1"];
[Self AddSubview:self.placeholderImageView];
}
return self;
}
@end

Viewcontroller.m

VIEWCONTROLLER.M//Sdwebimageviewplacehorder////Created by youxianming on 16/9/14. COPYRIGHT©2016 year 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 (0, 0, 150.F, 150.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 = 150.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

The above is a small series to introduce the development of iOS program using Placeholderimageview to achieve elegant picture loading effect, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.