diff --git a/TGPControls/TGPCamelLabels.h b/TGPControls/TGPCamelLabels.h index 2225f85..922883c 100644 --- a/TGPControls/TGPCamelLabels.h +++ b/TGPControls/TGPCamelLabels.h @@ -45,4 +45,7 @@ IB_DESIGNABLE @property (nonatomic) IBInspectable CGFloat downFontSize; @property (nonatomic) IBInspectable UIColor * downFontColor; +@property (nonatomic) IBInspectable CGFloat offCenter; +@property (nonatomic) IBInspectable NSInteger insets; + @end diff --git a/TGPControls/TGPCamelLabels.m b/TGPControls/TGPCamelLabels.m index 4aabf84..7eedf50 100644 --- a/TGPControls/TGPCamelLabels.m +++ b/TGPControls/TGPCamelLabels.m @@ -41,5 +41,7 @@ @dynamic downFontName; @dynamic downFontSize; @dynamic downFontColor; +@dynamic offCenter; +@dynamic insets; @end diff --git a/TGPControls/TGPCamelLabels7.h b/TGPControls/TGPCamelLabels7.h index 82e64c5..e8051fa 100644 --- a/TGPControls/TGPCamelLabels7.h +++ b/TGPControls/TGPCamelLabels7.h @@ -50,4 +50,10 @@ @property (nonatomic, assign) BOOL animate; // Make the labels animate when selected +// Label off-center to the left and right of the slider, expressed in label width. 0: none, -1/2 half out, 1/2 half in +@property (nonatomic, assign) CGFloat offCenter; + +// Label margins to the left and right of the slider +@property (nonatomic, assign) NSInteger insets; + @end diff --git a/TGPControls/TGPCamelLabels7.m b/TGPControls/TGPCamelLabels7.m index 90867da..786a365 100644 --- a/TGPControls/TGPCamelLabels7.m +++ b/TGPControls/TGPCamelLabels7.m @@ -157,6 +157,8 @@ _animationDuration = 0.15; _animate = YES; + _offCenter = 0.0; + _insets = 0; [self layoutTrack]; } @@ -171,13 +173,13 @@ } - (void)layoutTrack { - [self.upLabels enumerateObjectsUsingBlock:^(UIView * view, NSUInteger idx, BOOL *stop) { + for( UIView * view in self.upLabels) { [view removeFromSuperview]; - }]; + } [self.upLabels removeAllObjects]; - [self.dnLabels enumerateObjectsUsingBlock:^(UIView * view, NSUInteger idx, BOOL *stop) { + for( UIView * view in self.dnLabels) { [view removeFromSuperview]; - }]; + } [self.dnLabels removeAllObjects]; const NSUInteger count = self.names.count; @@ -198,7 +200,6 @@ upLabel.center = CGPointMake(centerX, centerY); upLabel.frame = ({ CGRect frame = upLabel.frame; - // frame.origin.y = 0; frame.origin.y = self.bounds.size.height - frame.size.height; frame; }); @@ -225,10 +226,28 @@ centerX += self.ticksDistance; } + + // Fix left and right label, if there are at least 2 labels + if( [self.names count] > 1) { + [self insetView:[self.upLabels firstObject] withInset:self.insets withMultiplier:self.offCenter]; + [self insetView:[self.upLabels lastObject] withInset:-self.insets withMultiplier:-self.offCenter]; + [self insetView:[self.dnLabels firstObject] withInset:self.insets withMultiplier:self.offCenter]; + [self insetView:[self.dnLabels lastObject] withInset:-self.insets withMultiplier:-self.offCenter]; + } + [self dockEffect:0.0]; } } +- (void) insetView:(UIView*)view withInset:(NSInteger)inset withMultiplier:(CGFloat)multiplier { + view.frame = ({ + CGRect frame = view.frame; + frame.origin.x += frame.size.width * multiplier; + frame.origin.x += inset; + frame; + }); +} + - (void)dockEffect:(NSTimeInterval)duration { const NSUInteger up = self.value;