SHARE
TWEET

Untitled

a guest Mar 20th, 2013 269 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  CoolProgress.h
  3.  
  4. #import <UIKit/UIKit.h>
  5.  
  6. @interface CoolProgress : UIView
  7.  
  8. @property (nonatomic, strong) UIColor *lightColor;
  9. @property (nonatomic, strong) UIColor *darkColor;
  10.  
  11. @property (nonatomic, assign) CGFloat progress;
  12.  
  13. @end
  14.  
  15.  
  16. //
  17. //  CoolProgress.m
  18.  
  19. #import "CoolProgress.h"
  20.  
  21. @interface CoolProgress ()
  22.  
  23. @property (strong, nonatomic) UIView *progressBar;
  24. @property (strong, nonatomic) UILabel *frontLabel;
  25. @property (strong, nonatomic) UILabel *backLabel;
  26.  
  27. @end
  28.  
  29. @implementation CoolProgress
  30.  
  31. - (void)setup {
  32.    
  33.     _backLabel = [[UILabel alloc] initWithFrame:self.bounds];
  34.     _backLabel.font = [UIFont boldSystemFontOfSize:17];
  35.     _backLabel.backgroundColor = [UIColor clearColor];
  36.     [self addSubview:_backLabel];
  37.    
  38.     _progressBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, self.bounds.size.height)];
  39.     _progressBar.clipsToBounds = YES;
  40.     [self addSubview:_progressBar];
  41.    
  42.     _frontLabel = [[UILabel alloc] initWithFrame:self.bounds];
  43.     _frontLabel.font = [UIFont boldSystemFontOfSize:17];
  44.     _frontLabel.adjustsFontSizeToFitWidth = NO;
  45.     _frontLabel.backgroundColor = [UIColor clearColor];
  46.     _frontLabel.autoresizingMask = 0x0;  // flexible right left and width
  47.     [_progressBar addSubview:_frontLabel];
  48.    
  49.     self.lightColor = [UIColor yellowColor];
  50.     self.darkColor = [UIColor blueColor];
  51. }
  52.  
  53. - (id)initWithFrame:(CGRect)frame
  54. {
  55.     self = [super initWithFrame:frame];
  56.     if (self) {
  57.         [self setup];
  58.     }
  59.     return self;
  60. }
  61.  
  62. - (id)initWithCoder:(NSCoder *)aDecoder {
  63.    
  64.     self = [super initWithCoder:aDecoder];
  65.     if (self) {
  66.         [self setup];
  67.     }
  68.     return self;
  69. }
  70.  
  71. - (void)setLightColor:(UIColor *)lightColor {
  72.    
  73.     _lightColor = lightColor;
  74.     self.progressBar.backgroundColor = lightColor;
  75.     self.backLabel.textColor = lightColor;
  76. }
  77.  
  78. - (void)setDarkColor:(UIColor *)darkColor {
  79.    
  80.     _darkColor = darkColor;
  81.     self.backgroundColor = darkColor;
  82.     self.frontLabel.textColor = darkColor;
  83. }
  84.  
  85. - (void)setProgress:(CGFloat)progress {
  86.    
  87.     _progress = progress;
  88.     self.progressBar.frame = CGRectMake(0, 0, progress*self.bounds.size.width, self.bounds.size.height);
  89.    
  90.     NSString *progressText = [NSString stringWithFormat:@"Progress %d%%", (int)floorf(progress*100)];
  91.     self.frontLabel.text = progressText;
  92.     self.backLabel.text = progressText;
  93. }
  94.  
  95. @end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top