From 5539e65448100215d63f3b315fe8804a445b32ae Mon Sep 17 00:00:00 2001 From: Loreto Parisi Date: Tue, 2 Jun 2015 02:11:53 +0200 Subject: [PATCH] Added JBWatchActivityIndicatorColorStyle --- .../Base.lproj/Main.storyboard | 297 +++++++----------- .../JBWatchActivityIndicator.h | 7 + .../JBWatchActivityIndicator.m | 14 +- JBWatchActivityIndicator/ViewController.h | 2 + JBWatchActivityIndicator/ViewController.m | 10 + 5 files changed, 148 insertions(+), 182 deletions(-) diff --git a/JBWatchActivityIndicator/Base.lproj/Main.storyboard b/JBWatchActivityIndicator/Base.lproj/Main.storyboard index e3a920b..622b678 100644 --- a/JBWatchActivityIndicator/Base.lproj/Main.storyboard +++ b/JBWatchActivityIndicator/Base.lproj/Main.storyboard @@ -1,186 +1,208 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -428,7 +360,12 @@ - + + + + + + diff --git a/JBWatchActivityIndicator/JBWatchActivityIndicator.h b/JBWatchActivityIndicator/JBWatchActivityIndicator.h index ada82c3..8bebe2f 100644 --- a/JBWatchActivityIndicator/JBWatchActivityIndicator.h +++ b/JBWatchActivityIndicator/JBWatchActivityIndicator.h @@ -52,9 +52,16 @@ typedef NS_ENUM(NSInteger, JBWatchActivityIndicatorSegmentStyle) { JBWatchActivityIndicatorSegmentStyleStroke }; +typedef NS_ENUM(NSInteger, JBWatchActivityIndicatorColorStyle) { + + JBWatchActivityIndicatorColorStyleWhite, + JBWatchActivityIndicatorColorStyleBlack +}; + @interface JBWatchActivityIndicator : NSObject @property (nonatomic, readwrite, assign) JBWatchActivityIndicatorSegmentStyle segmentStyle; +@property (nonatomic, readwrite, assign) JBWatchActivityIndicatorColorStyle colorStyle; @property (nonatomic, readwrite, assign) NSUInteger numberOfSegments; @property (nonatomic, readwrite, assign) CGFloat segmentRadius; @property (nonatomic, readwrite, assign) CGFloat strokeSpacingDegrees; diff --git a/JBWatchActivityIndicator/JBWatchActivityIndicator.m b/JBWatchActivityIndicator/JBWatchActivityIndicator.m index 2ffd10a..075b047 100644 --- a/JBWatchActivityIndicator/JBWatchActivityIndicator.m +++ b/JBWatchActivityIndicator/JBWatchActivityIndicator.m @@ -50,6 +50,7 @@ - (instancetype)initWithType:(JBWatchActivityIndicatorType)type { if (self) { _segmentStyle = JBWatchActivityIndicatorSegmentStyleCircle; + _colorStyle = JBWatchActivityIndicatorColorStyleWhite; _strokeSpacingDegrees = 1.0f; _indicatorRadius = 10.0f; _brightestAlpha = (254.0f / 255.0f); @@ -168,7 +169,11 @@ - (UIImage *)imageForFrameAtIndex:(NSUInteger)frameIndex { self.segmentRadius * 2.0f, self.segmentRadius * 2.0f)]; - [[UIColor colorWithWhite:1.0f alpha:alpha] setFill]; + if(self.colorStyle==JBWatchActivityIndicatorColorStyleBlack) { + [[UIColor colorWithWhite:0.3f alpha:alpha] setFill]; + } else { + [[UIColor colorWithWhite:1.0f alpha:alpha] setFill]; + } [path fill]; } else if (self.segmentStyle == JBWatchActivityIndicatorSegmentStyleStroke) { @@ -184,7 +189,12 @@ - (UIImage *)imageForFrameAtIndex:(NSUInteger)frameIndex { path.lineWidth = self.segmentRadius; path.lineCapStyle = kCGLineCapButt; - [[UIColor colorWithWhite:1.0f alpha:alpha] setStroke]; + if(self.colorStyle==JBWatchActivityIndicatorColorStyleBlack) { + [[UIColor colorWithWhite:0.3f alpha:alpha] setStroke]; + } else { + [[UIColor colorWithWhite:1.0f alpha:alpha] setStroke]; + } + [path stroke]; } } diff --git a/JBWatchActivityIndicator/ViewController.h b/JBWatchActivityIndicator/ViewController.h index 8d5096b..fa4b905 100644 --- a/JBWatchActivityIndicator/ViewController.h +++ b/JBWatchActivityIndicator/ViewController.h @@ -10,6 +10,8 @@ @interface ViewController : UIViewController +@property(nonatomic,strong) IBOutlet UIView *imageContainer; + @end diff --git a/JBWatchActivityIndicator/ViewController.m b/JBWatchActivityIndicator/ViewController.m index 7a81f90..1550530 100644 --- a/JBWatchActivityIndicator/ViewController.m +++ b/JBWatchActivityIndicator/ViewController.m @@ -15,6 +15,7 @@ @interface ViewController () @property (nonatomic, readwrite, weak) IBOutlet UIImageView *imageView; @property (nonatomic, readwrite, weak) IBOutlet UISegmentedControl *styleSegmentedControl; +@property (nonatomic, readwrite, weak) IBOutlet UISegmentedControl *colorSegmentedControl; @property (nonatomic, readwrite, weak) IBOutlet UIStepper *segmentsStepper; @property (nonatomic, readwrite, weak) IBOutlet UILabel *segmentsLabel; @property (nonatomic, readwrite, weak) IBOutlet UIStepper *segmentRadiusStepper; @@ -61,6 +62,7 @@ - (void)applyType:(JBWatchActivityIndicatorType)type { - (void)initializeControls { self.styleSegmentedControl.selectedSegmentIndex = self.watchActivityIndicator.segmentStyle; + self.colorSegmentedControl.selectedSegmentIndex=self.watchActivityIndicator.colorStyle; self.segmentsStepper.value = self.watchActivityIndicator.numberOfSegments; self.segmentRadiusStepper.value = self.watchActivityIndicator.segmentRadius; self.indicatorRadiusStepper.value = self.watchActivityIndicator.indicatorRadius; @@ -116,6 +118,14 @@ - (IBAction)segmentsButtonTouched:(UIButton *)sender { [self applyType:JBWatchActivityIndicatorTypeSegments]; } +- (IBAction)styleColorControlValueChanged:(UISegmentedControl *)sender { + + self.watchActivityIndicator.colorStyle = (JBWatchActivityIndicatorColorStyle)sender.selectedSegmentIndex; + self.imageContainer.backgroundColor = + self.watchActivityIndicator.colorStyle==JBWatchActivityIndicatorColorStyleWhite?[UIColor blackColor]:[UIColor whiteColor]; + [self update]; +} + - (IBAction)styleSegmentedControlValueChanged:(UISegmentedControl *)sender { self.watchActivityIndicator.segmentStyle = (JBWatchActivityIndicatorSegmentStyle)sender.selectedSegmentIndex;