-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from bcylin/feature/support-rotation
Support Device Rotation
- Loading branch information
Showing
6 changed files
with
266 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
SGNavigationProgress/UINavigationController+SGProgress/SGProgressView.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// SGProgressView.h | ||
// SGNavigationProgress | ||
// | ||
// Created by Ben on 19/03/2014. | ||
// Copyright (c) 2014 Ben. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface SGProgressView : UIView | ||
|
||
/** | ||
* The current progress shown by the receiver. | ||
* The progress value ranges from 0 to 1. The default value is 0. | ||
*/ | ||
@property (nonatomic, assign) float progress; | ||
|
||
@end |
66 changes: 66 additions & 0 deletions
66
SGNavigationProgress/UINavigationController+SGProgress/SGProgressView.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// SGProgressView.m | ||
// SGNavigationProgress | ||
// | ||
// Created by Ben on 19/03/2014. | ||
// Copyright (c) 2014 Ben. All rights reserved. | ||
// | ||
|
||
#import "SGProgressView.h" | ||
|
||
@interface SGProgressView () | ||
@property (nonatomic, strong) UIView *progressBar; | ||
@end | ||
|
||
@implementation SGProgressView | ||
|
||
- (void)setProgress:(float)progress { | ||
_progress = (progress < 0) ? 0 : | ||
(progress > 1) ? 1 : | ||
progress; | ||
|
||
CGRect slice, remainder; | ||
CGRectDivide(self.bounds, &slice, &remainder, CGRectGetWidth(self.bounds) * _progress, CGRectMinXEdge); | ||
|
||
if (!CGRectEqualToRect(self.progressBar.frame, slice)) { | ||
self.progressBar.frame = slice; | ||
} | ||
} | ||
|
||
#pragma mark - UIView | ||
|
||
- (instancetype)initWithFrame:(CGRect)frame | ||
{ | ||
if (self = [super initWithFrame:frame]) { | ||
self.frame = frame; | ||
self.clipsToBounds = YES; | ||
self.backgroundColor = [UIColor clearColor]; | ||
self.tintAdjustmentMode = UIViewTintAdjustmentModeNormal; | ||
self.progressBar = [[UIView alloc] init]; | ||
self.progressBar.backgroundColor = self.tintColor; | ||
self.progress = 0; | ||
[self addSubview:self.progressBar]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)setFrame:(CGRect)frame | ||
{ | ||
// 0.5 pt doesn't work well with autoresizingMask. | ||
frame.origin.y = ceilf(frame.origin.y); | ||
frame.size.height = floorf(frame.size.height); | ||
[super setFrame:frame]; | ||
|
||
__weak typeof(self)weakSelf = self; | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
weakSelf.progress = weakSelf.progress; | ||
}); | ||
} | ||
|
||
- (void)setTintColor:(UIColor *)tintColor | ||
{ | ||
[super setTintColor:tintColor]; | ||
self.progressBar.backgroundColor = tintColor; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.