From 53433b4bc2b90cdfaac19ee4660fd44746297200 Mon Sep 17 00:00:00 2001 From: arquebuse Date: Wed, 18 Feb 2015 11:17:27 -0800 Subject: [PATCH] Dynamic resizing of TGPControls --- TGPControls.podspec | 7 +++--- TGPControls.xcodeproj/project.pbxproj | 2 ++ TGPControls/TGPCamelLabels7.h | 3 ++- TGPControls/TGPCamelLabels7.m | 16 +++++++++++- TGPControls/TGPControlsTicksProtocol.h | 34 ++++++++++++++++++++++++++ TGPControls/TGPDiscreteSlider7.h | 3 +++ TGPControls/TGPDiscreteSlider7.m | 12 ++++++++- 7 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 TGPControls/TGPControlsTicksProtocol.h diff --git a/TGPControls.podspec b/TGPControls.podspec index 3f924c1..0d93851 100644 --- a/TGPControls.podspec +++ b/TGPControls.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "TGPControls" - s.version = "0.0.1" + s.version = "0.0.2" s.summary = "Custom Awesome iOS Controls." s.description = <<-DESC @@ -68,7 +68,7 @@ Pod::Spec.new do |s| # Supports git, hg, bzr, svn and HTTP. # - s.source = { :git => "https://github.com/arquebuse/TGPControls.git", :tag => "0.0.1" } + s.source = { :git => "https://github.com/arquebuse/TGPControls.git", :tag => "v0.0.2" } # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # @@ -80,7 +80,8 @@ Pod::Spec.new do |s| # s.source_files = "TGPControls", "TGPControls/**/*.{h,m}" - # s.exclude_files = "TGPControls/**/*.{h,m}" + s.exclude_files = "TGPControlsDemo7/*", "TGPControlsDemo/*" + s.public_header_files = "TGPControls/**/*.{h}" diff --git a/TGPControls.xcodeproj/project.pbxproj b/TGPControls.xcodeproj/project.pbxproj index 930e7ef..d44496e 100644 --- a/TGPControls.xcodeproj/project.pbxproj +++ b/TGPControls.xcodeproj/project.pbxproj @@ -50,6 +50,7 @@ DC101D6B1A75749600ECCF80 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DC101D7A1A75756300ECCF80 /* TGPControls_License.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = TGPControls_License.txt; sourceTree = ""; }; DC101D7B1A75756300ECCF80 /* TGPControls.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = TGPControls.podspec; sourceTree = ""; }; + DC28A54D1A947704003C9405 /* TGPControlsTicksProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TGPControlsTicksProtocol.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -76,6 +77,7 @@ children = ( DC0468E51A7596690084DE3E /* TGPCamelLabels.h */, DC0468E61A7596690084DE3E /* TGPCamelLabels.m */, + DC28A54D1A947704003C9405 /* TGPControlsTicksProtocol.h */, DC0468E81A7596930084DE3E /* TGPDiscreteSlider.h */, DC0468E91A7596930084DE3E /* TGPDiscreteSlider.m */, DC0468DF1A75962E0084DE3E /* TGPCamelLabels7.h */, diff --git a/TGPControls/TGPCamelLabels7.h b/TGPControls/TGPCamelLabels7.h index 9cb66e5..b1ff104 100644 --- a/TGPControls/TGPCamelLabels7.h +++ b/TGPControls/TGPCamelLabels7.h @@ -29,8 +29,9 @@ // THE SOFTWARE. #import +#import "TGPControlsTicksProtocol.h" -@interface TGPCamelLabels7 : UIControl +@interface TGPCamelLabels7 : UIControl @property (nonatomic) NSUInteger tickCount; // Only used if [labels count] < 1 @property (nonatomic) CGFloat ticksDistance; diff --git a/TGPControls/TGPCamelLabels7.m b/TGPControls/TGPCamelLabels7.m index 6ef181d..6ba884e 100644 --- a/TGPControls/TGPCamelLabels7.m +++ b/TGPControls/TGPCamelLabels7.m @@ -118,6 +118,14 @@ return self; } +// When bounds change, recalculate layout +- (void)setBounds:(CGRect)bounds +{ + [super setBounds:bounds]; + [self layoutTrack]; + [self setNeedsDisplay]; +} + // clickthrough -(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { for (UIView *view in self.subviews) { @@ -127,7 +135,7 @@ return NO; } -#pragma mark TGPCamelSlider +#pragma mark TGPCamelLabels - (void)initProperties { _ticksDistance = 44.0; @@ -282,4 +290,10 @@ [aView setAlpha:alpha]; } +#pragma mark - TGPControlsTicksProtocol + +-(void)tgpTicksDistanceChanged:(CGFloat)ticksDistance sender:(id)sender +{ + self.ticksDistance = ticksDistance; +} @end diff --git a/TGPControls/TGPControlsTicksProtocol.h b/TGPControls/TGPControlsTicksProtocol.h new file mode 100644 index 0000000..5ab2767 --- /dev/null +++ b/TGPControls/TGPControlsTicksProtocol.h @@ -0,0 +1,34 @@ +// @file: TGPControlsTicksProtocol.h +// @project: TGPControls +// +// @history: Created November 27, 2014 (Thanksgiving Day) +// @author: Xavier Schott +// mailto://xschott@gmail.com +// http://thegothicparty.com +// tel://+18089383634 +// +// @license: http://opensource.org/licenses/MIT +// Copyright (c) 2014, Xavier Schott +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +@protocol TGPControlsTicksProtocol +@required +-(void)tgpTicksDistanceChanged:(CGFloat)ticksDistance sender:(id)sender; +@end diff --git a/TGPControls/TGPDiscreteSlider7.h b/TGPControls/TGPDiscreteSlider7.h index 370b1d2..fea1cdc 100644 --- a/TGPControls/TGPDiscreteSlider7.h +++ b/TGPControls/TGPDiscreteSlider7.h @@ -29,6 +29,7 @@ // THE SOFTWARE. #import +#import "TGPControlsTicksProtocol.h" @interface TGPDiscreteSlider7 : @@ -61,6 +62,8 @@ typedef NS_ENUM(int, ComponentStyle) { @property (nonatomic) CGFloat thumbShadowRadius; @property (nonatomic) CGSize thumbShadowOffset; +@property (nonatomic, weak) NSObject * ticksListener; + // AKA: UISlider value (as CGFloat for compatibility with UISlider API, but expected to contain integers) @property (nonatomic) CGFloat minimumValue; @property (nonatomic) CGFloat value; diff --git a/TGPControls/TGPDiscreteSlider7.m b/TGPControls/TGPDiscreteSlider7.m index f5ce8b2..af577b3 100644 --- a/TGPControls/TGPDiscreteSlider7.m +++ b/TGPControls/TGPDiscreteSlider7.m @@ -128,6 +128,14 @@ static CGSize iosThumbShadowOffset = (CGSize){0, 3}; return _intValue; // calculated property, with a float-to-int adapter } +// When bounds change, recalculate layout +- (void)setBounds:(CGRect)bounds +{ + [super setBounds:bounds]; + [self layoutTrack]; + [self setNeedsDisplay]; +} + #pragma mark UIControl - (id)initWithCoder:(NSCoder *)aDecoder { @@ -351,8 +359,10 @@ static CGSize iosThumbShadowOffset = (CGSize){0, 3}; const CGFloat originX = (thumbWidth / 2) + (CGFloat)(trackLength * ratio); [self.ticksAbscisses addObject: [NSValue valueWithCGPoint:CGPointMake(originX, trackY)]]; } - [self layoutThumb]; + + // If we have a TGPDiscreteSliderTicksListener (such as TGPCamelLabels), broadcast new spacing + [self.ticksListener tgpTicksDistanceChanged:self.ticksDistance sender:self]; } - (void)layoutThumb {