├── .gitignore ├── AUTHORS ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SDWebImage-ProgressView.podspec ├── UIImageView+ProgressView.h └── UIImageView+ProgressView.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | PRIMARY AUTHORS 2 | Kevin Renskers - https://github.com/kevinrenskers 3 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | SDWebImage-ProgressView is an open source project and your contribution is very much appreciated. 3 | 4 | 1. Check for [open issues](https://github.com/kevinrenskers/SDWebImage-ProgressView/issues) or [open a fresh issue](https://github.com/kevinrenskers/SDWebImage-ProgressView/issues/new) to start a discussion around a feature idea or a bug. 5 | 2. Fork the [repository on Github](https://github.com/kevinrenskers/SDWebImage-ProgressView) and make your changes on the **develop** branch (or branch off of it). 6 | 3. Make sure to add yourself to AUTHORS and send a pull request. 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Kevin Renskers mixedCase.nl 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SDWebImage-ProgressView 2 | Category on UIImageView, adding a progress view while images are downloaded using SDWebImage (3.7.0 and up). 3 | [Example on Youtube](http://www.youtube.com/watch?v=qfZrOYYLOPc) 4 | 5 | 6 | ## Installation 7 | Use [Cocoapods](http://cocoapods.org): 8 | 9 | ``` 10 | pod 'SDWebImage-ProgressView' 11 | ``` 12 | 13 | ## Usage 14 | All of SDWebImage's UIView+WebCache methods gained an extra parameter: 15 | 16 | ``` 17 | - (void)sd_setImageWithURL:(NSURL *)url usingProgressView:(UIProgressView *)progressView; 18 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder usingProgressView:(UIProgressView *)progressView; 19 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options usingProgressView:(UIProgressView *)progressView; 20 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock usingProgressView:(UIProgressView *)progressView; 21 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock usingProgressView:(UIProgressView *)progressView; 22 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock usingProgressView:(UIProgressView *)progressView; 23 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock usingProgressView:(UIProgressView *)progressView; 24 | ``` 25 | 26 | Use `nil` for the `progressView` parameter to use the system default `UIProgressView`, or provide your own progress view (or subclass thereof) if you want custom styling and tint colors. 27 | 28 | If you're using the `sd_cancelCurrentImageLoad` method, you'll also have to call `removeProgressView` or you'll end up with lingering progress views. 29 | 30 | ``` 31 | - (void)prepareForReuse { 32 | [super prepareForReuse]; 33 | [self.imageView sd_cancelCurrentImageLoad]; 34 | [self.imageView removeProgressView]; 35 | } 36 | ``` 37 | 38 | ## Thanks 39 | The idea for this project came from [UIActivityIndicator-for-SDWebImage](https://github.com/JJSaccolo/UIActivityIndicator-for-SDWebImage). A big thank you goes to Giacomo Saccardo. 40 | 41 | 42 | ## License 43 | SDWebImage-ProgressView is available under the MIT license. See the LICENSE file for more info. 44 | -------------------------------------------------------------------------------- /SDWebImage-ProgressView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "SDWebImage-ProgressView" 3 | s.version = "0.6.0" 4 | s.summary = "Category on UIImageView, adding a progress view while images are downloaded using SDWebImage." 5 | s.homepage = "https://github.com/kevinrenskers/SDWebImage-ProgressView" 6 | s.license = 'MIT' 7 | s.author = { "Kevin Renskers" => "info@mixedcase.nl" } 8 | s.source = { :git => "https://github.com/kevinrenskers/SDWebImage-ProgressView.git", :tag => s.version.to_s } 9 | s.platform = :ios, '7.0' 10 | s.source_files = '*.{h,m}' 11 | s.requires_arc = true 12 | s.dependency 'SDWebImage' 13 | end 14 | -------------------------------------------------------------------------------- /UIImageView+ProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+ProgressView.h 3 | // 4 | // Created by Kevin Renskers on 07-06-13. 5 | // Copyright (c) 2013 Kevin Renskers. All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | @interface UIImageView (ProgressView) 12 | 13 | - (void)sd_setImageWithURL:(NSURL *)url usingProgressView:(UIProgressView *)progressView; 14 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder usingProgressView:(UIProgressView *)progressView; 15 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options usingProgressView:(UIProgressView *)progressView; 16 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDExternalCompletionBlock)completedBlock usingProgressView:(UIProgressView *)progressView; 17 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDExternalCompletionBlock)completedBlock usingProgressView:(UIProgressView *)progressView; 18 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDExternalCompletionBlock)completedBlock usingProgressView:(UIProgressView *)progressView; 19 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDExternalCompletionBlock)completedBlock usingProgressView:(UIProgressView *)progressView; 20 | - (void)removeProgressView; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /UIImageView+ProgressView.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+ProgressView.m 3 | // 4 | // Created by Kevin Renskers on 07-06-13. 5 | // Copyright (c) 2013 Kevin Renskers. All rights reserved. 6 | // 7 | 8 | #import "UIImageView+ProgressView.h" 9 | 10 | #define TAG_PROGRESS_VIEW 149462 11 | 12 | @implementation UIImageView (ProgressView) 13 | 14 | - (void)addProgressView:(UIProgressView *)progressView { 15 | UIProgressView *existingProgressView = (UIProgressView *)[self viewWithTag:TAG_PROGRESS_VIEW]; 16 | if (!existingProgressView) { 17 | if (!progressView) { 18 | progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]; 19 | } 20 | 21 | progressView.tag = TAG_PROGRESS_VIEW; 22 | progressView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin; 23 | 24 | float width = progressView.frame.size.width; 25 | float height = progressView.frame.size.height; 26 | float x = (self.frame.size.width / 2.0) - width/2; 27 | float y = (self.frame.size.height / 2.0) - height/2; 28 | progressView.frame = CGRectMake(x, y, width, height); 29 | 30 | [self addSubview:progressView]; 31 | } 32 | } 33 | 34 | - (void)updateProgress:(CGFloat)progress { 35 | UIProgressView *progressView = (UIProgressView *)[self viewWithTag:TAG_PROGRESS_VIEW]; 36 | if (progressView) { 37 | progressView.progress = progress; 38 | } 39 | } 40 | 41 | - (void)removeProgressView { 42 | UIProgressView *progressView = (UIProgressView *)[self viewWithTag:TAG_PROGRESS_VIEW]; 43 | if (progressView) { 44 | [progressView removeFromSuperview]; 45 | } 46 | } 47 | 48 | - (void)sd_setImageWithURL:(NSURL *)url usingProgressView:(UIProgressView *)progressView { 49 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil usingProgressView:progressView]; 50 | } 51 | 52 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder usingProgressView:(UIProgressView *)progressView { 53 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil usingProgressView:progressView]; 54 | } 55 | 56 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options usingProgressView:(UIProgressView *)progressView{ 57 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil usingProgressView:progressView]; 58 | } 59 | 60 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDExternalCompletionBlock)completedBlock usingProgressView:(UIProgressView *)progressView { 61 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock usingProgressView:progressView]; 62 | } 63 | 64 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDExternalCompletionBlock)completedBlock usingProgressView:(UIProgressView *)progressView { 65 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock usingProgressView:progressView]; 66 | } 67 | 68 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDExternalCompletionBlock)completedBlock usingProgressView:(UIProgressView *)progressView { 69 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock usingProgressView:progressView]; 70 | } 71 | 72 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDExternalCompletionBlock)completedBlock usingProgressView:(UIProgressView *)progressView { 73 | [self addProgressView:progressView]; 74 | 75 | __weak typeof(self) weakSelf = self; 76 | 77 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) { 78 | CGFloat progress = ((CGFloat)receivedSize / (CGFloat)expectedSize); 79 | dispatch_async(dispatch_get_main_queue(), ^{ 80 | [weakSelf updateProgress:progress]; 81 | }); 82 | 83 | if (progressBlock) { 84 | progressBlock(receivedSize, expectedSize, targetURL); 85 | } 86 | } 87 | completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 88 | [weakSelf removeProgressView]; 89 | if (completedBlock) { 90 | completedBlock(image, error, cacheType, imageURL); 91 | } 92 | }]; 93 | } 94 | 95 | @end 96 | --------------------------------------------------------------------------------