Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // CoolProgress.h
- #import <UIKit/UIKit.h>
- @interface CoolProgress : UIView
- @property (nonatomic, strong) UIColor *lightColor;
- @property (nonatomic, strong) UIColor *darkColor;
- @property (nonatomic, assign) CGFloat progress;
- @end
- //
- // CoolProgress.m
- #import "CoolProgress.h"
- @interface CoolProgress ()
- @property (strong, nonatomic) UIView *progressBar;
- @property (strong, nonatomic) UILabel *frontLabel;
- @property (strong, nonatomic) UILabel *backLabel;
- @end
- @implementation CoolProgress
- - (void)setup {
- _backLabel = [[UILabel alloc] initWithFrame:self.bounds];
- _backLabel.font = [UIFont boldSystemFontOfSize:17];
- _backLabel.backgroundColor = [UIColor clearColor];
- [self addSubview:_backLabel];
- _progressBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, self.bounds.size.height)];
- _progressBar.clipsToBounds = YES;
- [self addSubview:_progressBar];
- _frontLabel = [[UILabel alloc] initWithFrame:self.bounds];
- _frontLabel.font = [UIFont boldSystemFontOfSize:17];
- _frontLabel.adjustsFontSizeToFitWidth = NO;
- _frontLabel.backgroundColor = [UIColor clearColor];
- _frontLabel.autoresizingMask = 0x0; // flexible right left and width
- [_progressBar addSubview:_frontLabel];
- self.lightColor = [UIColor yellowColor];
- self.darkColor = [UIColor blueColor];
- }
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self setup];
- }
- return self;
- }
- - (id)initWithCoder:(NSCoder *)aDecoder {
- self = [super initWithCoder:aDecoder];
- if (self) {
- [self setup];
- }
- return self;
- }
- - (void)setLightColor:(UIColor *)lightColor {
- _lightColor = lightColor;
- self.progressBar.backgroundColor = lightColor;
- self.backLabel.textColor = lightColor;
- }
- - (void)setDarkColor:(UIColor *)darkColor {
- _darkColor = darkColor;
- self.backgroundColor = darkColor;
- self.frontLabel.textColor = darkColor;
- }
- - (void)setProgress:(CGFloat)progress {
- _progress = progress;
- self.progressBar.frame = CGRectMake(0, 0, progress*self.bounds.size.width, self.bounds.size.height);
- NSString *progressText = [NSString stringWithFormat:@"Progress %d%%", (int)floorf(progress*100)];
- self.frontLabel.text = progressText;
- self.backLabel.text = progressText;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement