Skip to content

Commit

Permalink
Large Progress View
Browse files Browse the repository at this point in the history
  • Loading branch information
tnys committed Feb 19, 2013
1 parent b102ade commit 60048cc
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 1 deletion.
6 changes: 6 additions & 0 deletions LargeProgressIndicator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
DB64ECF816D3BD1E001625F5 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DB64ECF716D3BD1E001625F5 /* Default-568h@2x.png */; };
DB64ECFB16D3BD1E001625F5 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DB64ECFA16D3BD1E001625F5 /* ViewController.m */; };
DB64ECFE16D3BD1E001625F5 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = DB64ECFC16D3BD1E001625F5 /* ViewController.xib */; };
DB64ED0616D3BD48001625F5 /* LargeProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = DB64ED0516D3BD48001625F5 /* LargeProgressView.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -37,6 +38,8 @@
DB64ECF916D3BD1E001625F5 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
DB64ECFA16D3BD1E001625F5 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
DB64ECFD16D3BD1E001625F5 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = "<group>"; };
DB64ED0416D3BD48001625F5 /* LargeProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LargeProgressView.h; sourceTree = "<group>"; };
DB64ED0516D3BD48001625F5 /* LargeProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LargeProgressView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -83,6 +86,8 @@
DB64ECE716D3BD1E001625F5 /* LargeProgressIndicator */ = {
isa = PBXGroup;
children = (
DB64ED0416D3BD48001625F5 /* LargeProgressView.h */,
DB64ED0516D3BD48001625F5 /* LargeProgressView.m */,
DB64ECF016D3BD1E001625F5 /* AppDelegate.h */,
DB64ECF116D3BD1E001625F5 /* AppDelegate.m */,
DB64ECF916D3BD1E001625F5 /* ViewController.h */,
Expand Down Expand Up @@ -176,6 +181,7 @@
DB64ECEE16D3BD1E001625F5 /* main.m in Sources */,
DB64ECF216D3BD1E001625F5 /* AppDelegate.m in Sources */,
DB64ECFB16D3BD1E001625F5 /* ViewController.m in Sources */,
DB64ED0616D3BD48001625F5 /* LargeProgressView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
18 changes: 18 additions & 0 deletions LargeProgressIndicator/LargeProgressView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// DesleeProgressView.h
// DesleeClama
//
// Created by Tom Nys on 14/02/13.
// Copyright (c) 2013 Netwalk VOF. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface LargeProgressView : UIView

@property (nonatomic) CGFloat progress;
@property (nonatomic, strong) UIColor* textColor;
@property (nonatomic, strong) UIColor* inactiveColor;
@property (nonatomic, strong) UIColor* shadowColor;

@end
109 changes: 109 additions & 0 deletions LargeProgressIndicator/LargeProgressView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// DesleeProgressView.m
// DesleeClama
//
// Created by Tom Nys on 14/02/13.
// Copyright (c) 2013 Netwalk VOF. All rights reserved.
//

#import "LargeProgressView.h"

@interface LargeProgressView()
{
UILabel* textLbl;
UILabel* percentLbl;
}
@end

@implementation LargeProgressView

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {

self.backgroundColor = [UIColor clearColor];
textLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height - 10)];
textLbl.font = [UIFont italicSystemFontOfSize:60];
textLbl.backgroundColor = [UIColor clearColor];
textLbl.shadowOffset = CGSizeMake(0, 2);
textLbl.textColor = [UIColor whiteColor];
textLbl.textAlignment = UITextAlignmentCenter;
textLbl.text = @"0";
[self addSubview:textLbl];

percentLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height/3 * 2, frame.size.width, 16)];
percentLbl.font = [UIFont italicSystemFontOfSize:14];
percentLbl.backgroundColor = [UIColor clearColor];
percentLbl.textColor = [UIColor grayColor];
percentLbl.shadowOffset = CGSizeMake(0, 1);
percentLbl.textAlignment = UITextAlignmentCenter;
percentLbl.text = NSLocalizedString(@"% loaded", nil);
[self addSubview:percentLbl];

self.textColor = [UIColor whiteColor];
self.inactiveColor = [UIColor colorWithWhite:.3 alpha:1.];
self.shadowColor = [UIColor grayColor];
}

return self;
}

-(void)setProgress:(CGFloat)progress
{
_progress = progress;
textLbl.text = [NSString stringWithFormat:@"%.0f", _progress * 100.];
[self setNeedsDisplay];
}

-(void)setShadowColor:(UIColor *)shadowColor
{
_shadowColor = shadowColor;
textLbl.shadowColor = shadowColor;
percentLbl.shadowColor = shadowColor;
}

-(void)setTextColor:(UIColor *)textColor
{
_textColor = textColor;
textLbl.textColor = _textColor;
percentLbl.textColor = _textColor;
}

-(void)setInactiveColor:(UIColor *)inactiveColor
{
_inactiveColor = inactiveColor;
}

- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();

CGFloat lineWidth = 10.;
CGFloat startAngle = - ((float)M_PI / 2); // 90 degrees
CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
CGFloat radius = (self.bounds.size.width - lineWidth)/2;
CGFloat endAngle = (self.progress * 2 * (float)M_PI) + startAngle;

CGContextSaveGState(ctx);
if (self.shadowColor)
{
CGContextSetShadowWithColor(ctx, CGSizeMake(0, 1), 1., self.shadowColor.CGColor);
}

UIBezierPath* outer = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(rect, lineWidth/2., lineWidth/2.)];
[_inactiveColor setStroke];
outer.lineWidth = lineWidth;
outer.lineCapStyle = kCGLineCapRound;
[outer stroke];
CGContextRestoreGState(ctx);

UIBezierPath *processPath = [UIBezierPath bezierPath];
processPath.lineCapStyle = kCGLineCapButt;
processPath.lineWidth = lineWidth;
[processPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
[_textColor set];
[processPath stroke];
}

@end
16 changes: 15 additions & 1 deletion LargeProgressIndicator/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "ViewController.h"
#import "LargeProgressView.h"

@interface ViewController ()

Expand All @@ -17,7 +18,20 @@ @implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

LargeProgressView* lpv = [[LargeProgressView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
lpv.center = self.view.center;
[self.view addSubview:lpv];

[NSTimer scheduledTimerWithTimeInterval:.25 target:self selector:@selector(updateProgress:) userInfo:lpv repeats:YES];
}

-(void)updateProgress:(NSTimer*)t
{
LargeProgressView* lpv = t.userInfo;
lpv.progress = lpv.progress + .01;
if (lpv.progress > 1.)
lpv.progress = 0.;
}

- (void)didReceiveMemoryWarning
Expand Down

0 comments on commit 60048cc

Please sign in to comment.