Skip to content

Commit 6ea8d8d

Browse files
Fixed Issue #32, and Added a new progress view.
1 parent 9d3c309 commit 6ea8d8d

File tree

12 files changed

+799
-38
lines changed

12 files changed

+799
-38
lines changed

Classes/NavigationController/UINavigationController+M13ProgressViewBar.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,17 @@
3636
- (void)cancelProgress;
3737
/**Wether or not the progress bar is showing.*/
3838
- (BOOL)isShowingProgressBar;
39+
/**
40+
The primary color of the progress bar if you do not want it to be the same as the UINavigationBar's tint color. If set to nil, the UINavigationBar's tint color will be used.
41+
42+
@param primaryColor The color to set.
43+
*/
44+
- (void)setPrimaryColor:(UIColor *)primaryColor;
45+
/**
46+
The secondary color of the progress bar, if nil, the secondary color will be the barTintColor.
47+
48+
@param secondaryColor The color to set.
49+
*/
50+
- (void)setSecondaryColor:(UIColor *)secondaryColor;
3951

4052
@end

Classes/NavigationController/UINavigationController+M13ProgressViewBar.m

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
static char indeterminateKey;
1818
static char indeterminateLayerKey;
1919
static char isShowingProgressKey;
20+
static char primaryColorKey;
21+
static char secondaryColorKey;
2022

2123
@implementation UINavigationController (M13ProgressViewBar)
2224

@@ -156,6 +158,9 @@ - (void)updateProgressWithInterfaceOrientation:(UIInterfaceOrientation)interface
156158
{
157159
progressView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 2.5)];
158160
progressView.backgroundColor = self.navigationBar.tintColor;
161+
if ([self getPrimaryColor]) {
162+
progressView.backgroundColor = [self getPrimaryColor];
163+
}
159164
progressView.clipsToBounds = YES;
160165
[self setProgressView:progressView];
161166
}
@@ -243,11 +248,32 @@ - (void)drawIndeterminateWithInterfaceOrientation:(UIInterfaceOrientation)interf
243248
//Start the image context
244249
UIGraphicsBeginImageContextWithOptions(CGSizeMake(stripeWidth * 4.0, stripeWidth * 4.0), NO, [UIScreen mainScreen].scale);
245250
//Fill the background
251+
if ([self getPrimaryColor]) {
252+
[[self getPrimaryColor] setFill];
253+
} else {
246254
[self.navigationBar.tintColor setFill];
255+
}
247256
UIBezierPath *fillPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, stripeWidth * 4.0, stripeWidth * 4.0)];
248257
[fillPath fill];
249258
//Draw the stripes
250-
[self.navigationBar.barTintColor setFill];
259+
//Set the stripe color
260+
if ([self getSecondaryColor]) {
261+
[[self getSecondaryColor] setFill];
262+
} else {
263+
CGFloat red;
264+
CGFloat green;
265+
CGFloat blue;
266+
CGFloat alpha;
267+
[self.navigationBar.barTintColor getRed:&red green:&green blue:&blue alpha:&alpha];
268+
//System set the tint color to a close to, but not non-zero value for each component.
269+
if (alpha > .05) {
270+
[self.navigationBar.barTintColor setFill];
271+
} else {
272+
[[UIColor whiteColor] setFill];
273+
}
274+
275+
}
276+
251277
for (int i = 0; i < 4; i++) {
252278
//Create the four inital points of the fill shape
253279
CGPoint bottomLeft = CGPointMake(-(stripeWidth * 4.0), stripeWidth * 4.0);
@@ -423,4 +449,27 @@ - (BOOL)isShowingProgressBar
423449
return objc_getAssociatedObject(self, &isShowingProgressKey);
424450
}
425451

452+
- (void)setPrimaryColor:(UIColor *)primaryColor
453+
{
454+
objc_setAssociatedObject(self, &primaryColorKey, primaryColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
455+
[self getProgressView].backgroundColor = primaryColor;
456+
[self setIndeterminate:[self getIndeterminate]];
457+
}
458+
459+
- (UIColor *)getPrimaryColor
460+
{
461+
return objc_getAssociatedObject(self, &primaryColorKey);
462+
}
463+
464+
- (void)setSecondaryColor:(UIColor *)secondaryColor
465+
{
466+
objc_setAssociatedObject(self, &secondaryColorKey, secondaryColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
467+
[self setIndeterminate:[self getIndeterminate]];
468+
}
469+
470+
- (UIColor *)getSecondaryColor
471+
{
472+
return objc_getAssociatedObject(self, &secondaryColorKey);
473+
}
474+
426475
@end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// M13ProgressViewLetterpress.h
3+
// M13ProgressSuite
4+
//
5+
// Created by Brandon McQuilkin on 4/28/14.
6+
// Copyright (c) 2014 Brandon McQuilkin. All rights reserved.
7+
//
8+
9+
#import "M13ProgressView.h"
10+
11+
typedef enum {
12+
M13ProgressViewLetterpressPointShapeSquare,
13+
M13ProgressViewLetterpressPointShapeCircle
14+
} M13ProgressViewLetterpressPointShape;
15+
16+
@interface M13ProgressViewLetterpress : M13ProgressView
17+
/**@name Properties*/
18+
/**
19+
The number of grid points in each direction.
20+
*/
21+
@property (nonatomic, assign) CGPoint numberOfGridPoints;
22+
/**
23+
The shape of the grid points.
24+
*/
25+
@property (nonatomic, assign) M13ProgressViewLetterpressPointShape pointShape;
26+
/**
27+
The amount of space between the grid points.
28+
*/
29+
@property (nonatomic, assign) CGFloat pointSpacing;
30+
/**
31+
The size of the notch to carve out on one side.
32+
*/
33+
@property (nonatomic, assign) CGSize notchSize;
34+
/**
35+
The spring constant that defines the amount of "spring" the progress view has in its animation.
36+
*/
37+
@property (nonatomic, assign) CGFloat springConstant;
38+
/**
39+
The constant that determines how long the progress view "bounces" for.
40+
*/
41+
@property (nonatomic, assign) CGFloat dampingCoefficient;
42+
/**
43+
The constant that determines how much the springConstant and dampingCoefficent affect the animation.
44+
*/
45+
@property (nonatomic, assign) CGFloat mass;
46+
47+
@end

0 commit comments

Comments
 (0)