Load images with SDWebImage gradient,

Source: Internet
Author: User

Load images with SDWebImage gradient,

Loading images with SDWebImage gradient

 

Use

For details about how to use the source code, you only need to specify an image address and a placeHolder image (not required.

 

Effect

 

Source code

SDWebImageViewPlaceHorder in https://github.com/YouXianMing/UI-Component-Collection

//// PlaceholderImageView. h // SDWebImageViewPlaceHorder /// Created by YouXianMing on 16/8/19. // 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;/** PlaceholderImageView's constractor. @ param frame The Frame. @ param image The placeholderImage. @ return The PlaceholderImageView's instancetype. * // + (instancetype) placeholderImageViewWithFrame :( CGRect) frame placeholderImage :( UIImage *) image; @ end
//// PlaceholderImageView. m // SDWebImageViewPlaceHorder /// Created by YouXianMing on 16/8/19. // Copyright 2016 YouXianMing. all rights reserved. // # import "PlaceholderImageView. h "# import" UIImageView + WebCache. h "@ interface PlaceholderImageView () @ property (nonatomic, strong) UIImageView * placeHoderImageView; @ property (nonatomic, strong) UIImageView * handle; @ property (nonatomic, strong) NSString * pUrlString; @ end @ implementation PlaceholderImageView-(void) layoutSubviews {[super layoutSubviews]; self. placeHoderImageView. frame = self. bounds; self. contentImageView. frame = self. bounds;}-(instancetype) initWithFrame :( CGRect) frame {if (self = [super initWithFrame: frame]) {self. layer. masksToBounds = YES; self. placeHoderImageView = [[UIImageView alloc] initWithFrame: self. bounds]; self. contentImageView = [[UIImageView alloc] initWithFrame: self. bounds]; [self addSubview: self. placeHoderImageView]; [self addSubview: self. contentImageView]; self. contentImageContentMode = UIViewContentModeScaleAspectFill; self. inline = inline;} return self;} + (instancetype) inline :( CGRect) frame placeholderImage :( UIImage *) image {PlaceholderImageView * placeHolderImageView = [[PlaceholderImageView alloc] initWithFrame: frame]; placeHolderImageView. placeholderImage = image; return placeHolderImageView;} # pragma mark-Setter & Getter. -(void) setPlaceholderImage :( UIImage *) placeholderImage {_ placeHoderImageView. image = placeholderImage;}-(UIImage *) placeholderImage {return _ placeHoderImageView. image;}-(void) setUrlString :( NSString *) urlString {_ pUrlString = urlString; _ contentImageView. alpha = 0.f; NSURL * url = [NSURL URLWithString: urlString]; [_ contentImageView parameters: url completed: ^ (UIImage * image, NSError * error, SDImageCacheType cacheType, NSURL * imageURL) {if (image) {// Image load from disk or download from network. if (cacheType = SDImageCacheTypeNone | cacheType = SDImageCacheTypeDisk) {[UIView animateWithDuration: 0.5f animations: ^ {_ contentImageView. alpha = 1.f;}] ;}else {_ contentImageView. alpha = 1.f;}}] ;}- (NSString *) urlString {return _ pUrlString ;}- (void) setPlaceholderImageContentMode :( UIViewContentMode) placeholderImageContentMode {_ placeHoderImageView. contentMode = placeholderImageContentMode;}-(UIViewContentMode) placeholderImageContentMode {return _ placeHoderImageView. contentMode;}-(void) setContentImageContentMode :( UIViewContentMode) contentImageContentMode {_ contentImageView. contentMode = contentImageContentMode;}-(UIViewContentMode) contentImageContentMode {return _ contentImageView. contentMode;} @ end

 

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.