From 3ab980908567a84861afb8c1c0a8f1b92cbfa239 Mon Sep 17 00:00:00 2001 From: Iulian Onofrei Date: Thu, 22 Jun 2017 17:52:44 +0300 Subject: [PATCH 1/2] Add Cocoapods spec file --- LUNSegmentedControl.podspec.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 LUNSegmentedControl.podspec.json diff --git a/LUNSegmentedControl.podspec.json b/LUNSegmentedControl.podspec.json new file mode 100644 index 0000000..a776b87 --- /dev/null +++ b/LUNSegmentedControl.podspec.json @@ -0,0 +1,23 @@ +{ + "name": "LUNSegmentedControl", + "version": "1.0.7", + "summary": "Customizable segmented control with interaсtive animation. It provide liquid shape for selection.", + "description": "Customizable segmented control with interactive animation, liquid shape of selection, gradients for each state and shadow.", + "homepage": "https://github.com/LunApps/LUNSegmentedControl", + "license": { + "type": "MIT", + "file": "LICENSE" + }, + "authors": { + "Andrii Selivanov": "andrey@lunapps.com" + }, + "platforms": { + "ios": "8.0" + }, + "source": { + "git": "https://github.com/LunApps/LUNSegmentedControl.git", + "tag": "1.0.7" + }, + "source_files": "LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl/*.{h,m}", + "requires_arc": true +} From af4fdc76153f8a12d3cd088a31645985894d069d Mon Sep 17 00:00:00 2001 From: Iulian Onofrei Date: Thu, 22 Jun 2017 17:54:56 +0300 Subject: [PATCH 2/2] Add delegate to customize selected view's shadow --- .../LUNSegmentedControl/LUNSegmentedControl.h | 7 +++++++ .../LUNSegmentedControl/LUNSegmentedControl.m | 11 ++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl.h b/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl.h index fa3ed9a..bb4863b 100644 --- a/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl.h +++ b/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl.h @@ -103,6 +103,13 @@ typedef NS_ENUM(NSUInteger, LUNSegmentedControlBounce) { * @see segmentedControl:setupStateAtIndex:stateView:selectedView:withSelectionPercent: */ - (void)segmentedControl:(LUNSegmentedControl *)segmentedControl resetStateAtIndex:(NSInteger)stateIndex stateView:(UIView *)stateView selectedView:(UIView *)selectedView; +/** + * @brief Asks the delegate to setup shadow. + * + * @param segmentedControl LUNSegmentedControl instance that asks delegate. + * @param shadowView Shadow view. + */ +- (void)segmentedControl:(LUNSegmentedControl *)segmentedControl setupShadowView:(UIView *)shadowView; @end diff --git a/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl.m b/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl.m index cf71cac..79a55f8 100644 --- a/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl.m +++ b/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl/LUNSegmentedControl.m @@ -617,9 +617,14 @@ - (UIColor *)shadowColorForStateAtIndex:(NSInteger)index { return self.selectorViewColor; } - (void)setupShadowForStateAtIndex:(NSInteger)index visible:(BOOL)visible animated:(BOOL)animated { - self.shadowView.layer.shadowColor = [self shadowColorForStateAtIndex:index].CGColor; - self.shadowView.layer.shadowRadius = 7.0; - self.shadowView.layer.shadowOffset = CGSizeMake(0, 5); + if ([self.delegate respondsToSelector:@selector(segmentedControl:setupShadowView:)]) { + [self.delegate segmentedControl:self setupShadowView:self.shadowView]; + } else { + self.shadowView.layer.shadowColor = [self shadowColorForStateAtIndex:index].CGColor; + self.shadowView.layer.shadowRadius = 7.0; + self.shadowView.layer.shadowOffset = CGSizeMake(0, 5); + } + CGAffineTransform transform = CGAffineTransformMakeTranslation(self.stateViews[index].bounds.size.width * [self percentFromOffset:[self offsetFromState:index]], 0); CGPathRef transformedPath = CGPathCreateCopyByTransformingPath([self pathForSelectorViewFromPercentage:0], &transform); self.shadowView.layer.shadowPath = transformedPath;