Skip to content

Commit 9664101

Browse files
committed
Changes structure of folders. Try to change headers.
1 parent 7a50e2a commit 9664101

9 files changed

+345
-3
lines changed

CHANGELOG

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*** 0.1.0 ***
2+
- First upload.
3+
4+
*** 0.x.x ***
5+
-
6+
-
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// CircularProgressViewSettings.h
3+
//
4+
//
5+
// Created by Nik Kov on 13.09.16.
6+
// Copyright © 2016 Nik Kov. All rights reserved.
7+
//
8+
9+
@interface CircularProgressViewSettings : NSObject
10+
11+
/// Color of background of a track
12+
@property (nonatomic, strong) UIColor *trackTintColor;
13+
/// Color of circle, that filling track
14+
@property (nonatomic, strong) UIColor *progressTintColor;
15+
/// Color of circle inside the progress view
16+
@property (nonatomic, strong) UIColor *innerTintColor;
17+
/// Rounded corner of progress. On/Off. Between 0 and 1.
18+
@property (nonatomic) NSInteger roundedCorners;
19+
/// Thickness of progress
20+
@property (nonatomic) CGFloat thicknessRatio;
21+
/// Сounterclockwise or clockwise filling. On/Off. Between 0 and 1.
22+
@property (nonatomic) NSInteger clockwiseProgress;
23+
/// Progress state
24+
@property (nonatomic) CGFloat progress;
25+
26+
/// If you don't know the size of data. Speed.
27+
@property (nonatomic) CGFloat indeterminateDuration;
28+
/// If you don't know the size of data. On/Off. Between 0 and 1.
29+
@property (nonatomic) NSInteger indeterminate;
30+
31+
@end
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// CircularProgressViewSettings.m
3+
//
4+
//
5+
// Created by Nik Kov on 13.09.16.
6+
// Copyright © 2016 Nik Kov. All rights reserved.
7+
//
8+
9+
#import "CircularProgressViewSettings.h"
10+
11+
@implementation CircularProgressViewSettings
12+
13+
@end

Classes/LinearProgressViewSettings.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// LinearProgressViewSettings.h
3+
//
4+
//
5+
// Created by Nik Kov on 13.09.16.
6+
// Copyright © 2016 Nik Kov. All rights reserved.
7+
//
8+
9+
@interface LinearProgressViewSettings : NSObject
10+
11+
@property (nonatomic) float progress;
12+
@property (nonatomic, strong) UIColor* progressTintColor;
13+
@property (nonatomic, strong) UIColor* trackTintColor;
14+
@property (nonatomic, strong) UIImage* progressImage;
15+
@property (nonatomic, strong) UIImage* trackImage;
16+
17+
@end

Classes/LinearProgressViewSettings.m

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// LinearProgressViewSettings.m
3+
//
4+
//
5+
// Created by Nik Kov on 13.09.16.
6+
// Copyright © 2016 Nik Kov. All rights reserved.
7+
//
8+
9+
#import "LinearProgressViewSettings.h"
10+
11+
@implementation LinearProgressViewSettings
12+
13+
@end
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// UIImageView+CircularProgressView.h
3+
//
4+
//
5+
// Created by Nik Kov on 13.09.16.
6+
// Copyright © 2016 Nik Kov. All rights reserved.
7+
//
8+
9+
#import "CircularProgressViewSettings.h"
10+
#import "LinearProgressViewSettings.h"
11+
#import <DACircularProgress/DACircularProgressView.h>
12+
#import <SDWebImage/UIImageView+WebCache.h>
13+
14+
15+
typedef enum : NSUInteger {
16+
LinearPV = 1,
17+
CircularPV,
18+
} ProgressViewType;
19+
20+
@protocol ProgressViewDataSource <NSObject>
21+
22+
@optional
23+
- (LinearProgressViewSettings *)setupLinearProgressViewSettings;
24+
- (CircularProgressViewSettings *)setupCircularProgressViewSettings;
25+
26+
@end
27+
28+
29+
@interface UIImageView (CircularProgressView)
30+
31+
#pragma mark - Progress view settings
32+
/** Delegate to customize your ProgressView if you had choosen one from ProgressViewType.
33+
* @param Delegate that responds to <ProgressViewDataSource> protocol
34+
*/
35+
- (void)nkvSetProgressViewDataSource:(id <ProgressViewDataSource>)nkvDataSource;
36+
37+
#pragma mark - Image setting methods
38+
- (void)nkv_setImageWithURL:(NSURL *)url usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView;
39+
- (void)nkv_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView;
40+
- (void)nkv_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView;
41+
- (void)nkv_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView;
42+
- (void)nkv_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView;
43+
- (void)nkv_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView;
44+
- (void)nkv_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView;
45+
46+
- (void)removeProgressView;
47+
48+
49+
@end
50+
+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
//
2+
// UIImageView+CircularProgressView.m
3+
//
4+
//
5+
// Created by Nik Kov on 13.09.16.
6+
// Copyright © 2016 Nik Kov. All rights reserved.
7+
//
8+
9+
#import "UIImageView+CircularProgressView.h"
10+
11+
#define TAG_PROGRESS_VIEW 777333777
12+
13+
@implementation UIImageView (CircularProgressView)
14+
15+
id <ProgressViewDataSource> dataSource;
16+
17+
#pragma mark - Custom ProgressView
18+
- (void)addCustomProgressView:(UIProgressView *)customProgressView
19+
{
20+
UIProgressView *existingProgressView = (UIProgressView *)[self viewWithTag:TAG_PROGRESS_VIEW];
21+
22+
if ( ! existingProgressView)
23+
{
24+
[self setupFrameAndAttributesForProgressView:customProgressView];
25+
[self addSubview:customProgressView];
26+
}
27+
}
28+
29+
#pragma mark - Linear ProgressView
30+
- (void)addLinearProgressView
31+
{
32+
UIProgressView *existingProgressView = (UIProgressView *)[self viewWithTag:TAG_PROGRESS_VIEW];
33+
34+
if ( ! existingProgressView)
35+
{
36+
UIProgressView *linearProgressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
37+
[self setupFrameAndAttributesForProgressView:linearProgressView];
38+
39+
if ( dataSource )
40+
{
41+
if ( [dataSource respondsToSelector:@selector(setupLinearProgressViewSettings)] )
42+
{
43+
LinearProgressViewSettings *settings = [dataSource setupLinearProgressViewSettings];
44+
if ( ! settings )
45+
NSLog(@"Please, be sure, you are returning something in <setupLinearProgressViewSettings> method in your Data Source.");
46+
else
47+
{
48+
linearProgressView.progress = settings.progress;
49+
linearProgressView.progressTintColor = settings.progressTintColor;
50+
linearProgressView.trackTintColor = settings.trackTintColor;
51+
linearProgressView.progressImage = settings.progressImage;
52+
linearProgressView.trackImage = settings.trackImage;
53+
}
54+
}
55+
else
56+
NSLog(@"Please, implement <setupLinearProgressViewSettings> method in your Data Source.");
57+
}
58+
59+
[self addSubview:linearProgressView];
60+
}
61+
}
62+
63+
#pragma mark - Circular ProgressView
64+
65+
- (void)addCircularProgressView
66+
{
67+
DACircularProgressView *existingProgressView = (DACircularProgressView *)[self viewWithTag:TAG_PROGRESS_VIEW];
68+
69+
if ( ! existingProgressView)
70+
{
71+
DACircularProgressView *circularProgressView = [[DACircularProgressView alloc] init];
72+
[self setupFrameAndAttributesForProgressView:circularProgressView];
73+
74+
if ( dataSource )
75+
{
76+
if ( ! [dataSource respondsToSelector:@selector(setupCircularProgressViewSettings)] )
77+
NSLog(@"Please, implement <setupCircularProgressViewSettings> method in your Data Source.");
78+
else
79+
{
80+
CircularProgressViewSettings *settings = [dataSource setupCircularProgressViewSettings];
81+
if ( ! settings )
82+
NSLog(@"Please, be sure, you are returning something in <setupCircularProgressViewSettings> method in your Data Source.");
83+
else
84+
{
85+
circularProgressView.trackTintColor = settings.trackTintColor;
86+
circularProgressView.progressTintColor = settings.progressTintColor;
87+
circularProgressView.innerTintColor = settings.innerTintColor;
88+
circularProgressView.roundedCorners = settings.roundedCorners;
89+
circularProgressView.thicknessRatio = settings.thicknessRatio;
90+
circularProgressView.clockwiseProgress = settings.clockwiseProgress;
91+
circularProgressView.progress = settings.progress;
92+
circularProgressView.indeterminateDuration = settings.indeterminateDuration;
93+
circularProgressView.indeterminate = settings.indeterminate;
94+
}
95+
}
96+
}
97+
98+
[self addSubview:circularProgressView];
99+
}
100+
}
101+
102+
#pragma mark - Update and delete ProgressView
103+
104+
- (void)updateProgress:(CGFloat)progress
105+
{
106+
UIProgressView *progressView = (UIProgressView *)[self viewWithTag:TAG_PROGRESS_VIEW];
107+
if (progressView)
108+
progressView.progress = progress;
109+
}
110+
111+
- (void)removeProgressView
112+
{
113+
UIView *progressView = [self viewWithTag:TAG_PROGRESS_VIEW];
114+
if (progressView)
115+
[progressView removeFromSuperview];
116+
}
117+
118+
#pragma mark - Image setting methods
119+
120+
- (void)nkv_setImageWithURL:(NSURL *)url usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView
121+
{
122+
[self nkv_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil usingProgressViewType:progressViewType orCustomProgressView:progressView];
123+
}
124+
125+
- (void)nkv_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView
126+
{
127+
[self nkv_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil usingProgressViewType:progressViewType orCustomProgressView:progressView];
128+
}
129+
130+
- (void)nkv_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView
131+
{
132+
[self nkv_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil usingProgressViewType:progressViewType orCustomProgressView:progressView];
133+
}
134+
135+
- (void)nkv_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView
136+
{
137+
[self nkv_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock usingProgressViewType:progressViewType orCustomProgressView:progressView];
138+
}
139+
140+
- (void)nkv_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView
141+
{
142+
[self nkv_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock usingProgressViewType:progressViewType orCustomProgressView:progressView];
143+
}
144+
145+
- (void)nkv_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView
146+
{
147+
[self nkv_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock usingProgressViewType:progressViewType orCustomProgressView:progressView];
148+
}
149+
150+
- (void)nkv_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock usingProgressViewType:(ProgressViewType)progressViewType orCustomProgressView:(UIProgressView *)progressView
151+
{
152+
if (progressView)
153+
[self addCustomProgressView:progressView];
154+
else
155+
switch (progressViewType)
156+
{
157+
case CircularPV:
158+
{
159+
[self addCircularProgressView];
160+
break;
161+
}
162+
case LinearPV:
163+
default:
164+
{
165+
[self addLinearProgressView];
166+
break;
167+
}
168+
}
169+
170+
__weak typeof(self) weakSelf = self;
171+
[self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) {
172+
173+
CGFloat progress = ((CGFloat)receivedSize / (CGFloat)expectedSize);
174+
dispatch_async(dispatch_get_main_queue(), ^{
175+
[weakSelf updateProgress:progress];
176+
});
177+
178+
if (progressBlock)
179+
progressBlock(receivedSize, expectedSize);
180+
}
181+
182+
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
183+
[weakSelf removeProgressView];
184+
if (completedBlock)
185+
completedBlock(image, error, cacheType, imageURL);
186+
}];
187+
}
188+
189+
#pragma mark - Accessors and Others
190+
191+
- (void)setupFrameAndAttributesForProgressView:(UIView*)view;
192+
{
193+
view.tag = TAG_PROGRESS_VIEW;
194+
view.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
195+
196+
float width = view.frame.size.width;
197+
float height = view.frame.size.height;
198+
float x = (self.frame.size.width / 2.0) - width / 2;
199+
float y = (self.frame.size.height / 2.0) - height / 2;
200+
view.frame = CGRectMake(x, y, width, height);
201+
}
202+
203+
- (void)nkvSetProgressViewDataSource:(id<ProgressViewDataSource>)nkvDataSource
204+
{
205+
dataSource = nkvDataSource;
206+
}
207+
208+
@end
209+

SDWebImage-CircularProgressView.podspec

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ Pod::Spec.new do |s|
99
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
1010
s.license = { :type => 'MIT', :file => 'LICENSE' }
1111
s.author = { "Nik Kov" => "[email protected]" }
12-
s.source = { :git => "https://github.com/NikKovV/SDWebImage-CircularProgressView.git", :tag => s.version.to_s }
12+
s.source = {
13+
:git => "https://github.com/NikKovV/SDWebImage-CircularProgressView.git",
14+
:tag => s.version.to_s
15+
}
1316
s.ios.deployment_target = '8.0'
14-
s.source_files = '*.{h,m}'
17+
s.source_files = 'Classes/*.{h,m}'
1518
s.requires_arc = true
1619
s.frameworks = 'UIKit'
1720
s.dependency 'SDWebImage', '~> 3.7.0'

UIImageView+CircularProgressView.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import "CircularProgressViewSettings.h"
1010
#import "DACircularProgressView.h"
1111
#import "LinearProgressViewSettings.h"
12-
#import "UIImageView+WebCache.h"
12+
#import <SDWebImage/UIImageView+WebCache.h>
1313

1414

1515
typedef enum : NSUInteger {

0 commit comments

Comments
 (0)