Skip to content

Commit 545cdf3

Browse files
Fixed #5 - Provide a mechanism to hide thumb
1 parent 6aa62c5 commit 545cdf3

1 file changed

Lines changed: 70 additions & 68 deletions

File tree

TGPControls/TGPDiscreteSlider7.m

Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ - (CGFloat)minimumValue {
120120
- (void)setValue:(CGFloat)value {
121121
const unsigned int nonZeroIncrement = ((0 == _incrementValue) ? 1 : _incrementValue);
122122
const int rootValue = ((value - self.minimumValue) / nonZeroIncrement);
123-
_intValue = self.minimumValue + (rootValue * nonZeroIncrement);
123+
_intValue = self.minimumValue + (int)(rootValue * nonZeroIncrement);
124124
[self layoutTrack];
125125
}
126126

@@ -267,76 +267,78 @@ - (void)drawTrack {
267267
}
268268

269269
- (void)drawThumb {
270-
const CGSize thumbSizeForStyle = [self thumbSizeIncludingShadow];
271-
const CGFloat thumbWidth = thumbSizeForStyle.width;
272-
const CGFloat thumbHeight = thumbSizeForStyle.height;
273-
const CGRect rectangle = CGRectMake(self.thumbAbscisse - (thumbWidth / 2),
274-
(self.frame.size.height - thumbHeight)/2,
275-
thumbWidth,
276-
thumbHeight);
277-
278-
const CGFloat shadowRadius = ((self.thumbStyle == ComponentStyleIOS)
279-
? iOSThumbShadowRadius
280-
: self.thumbShadowRadius);
281-
const CGSize shadowOffset = ((self.thumbStyle == ComponentStyleIOS)
282-
? iosThumbShadowOffset
283-
: self.thumbShadowOffset);
284-
285-
self.thumbLayer.frame = ((shadowRadius != 0.0) // Ignore offset if there is no shadow
286-
? CGRectInset(rectangle,
287-
shadowRadius + shadowOffset.width,
288-
shadowRadius + shadowOffset.height)
289-
: CGRectInset(rectangle, shadowRadius, shadowRadius));
290-
291-
switch(self.thumbStyle) {
292-
case ComponentStyleRounded: // A rounded thumb is circular
293-
self.thumbLayer.backgroundColor = [self.thumbColor CGColor];
294-
self.thumbLayer.borderColor = [[UIColor clearColor] CGColor];
295-
self.thumbLayer.borderWidth = 0.0;
296-
self.thumbLayer.cornerRadius = self.thumbLayer.frame.size.width/2;
297-
self.thumbLayer.allowsEdgeAntialiasing = YES;
298-
break;
299-
300-
case ComponentStyleRectangular:
301-
self.thumbLayer.backgroundColor = [self.thumbColor CGColor];
302-
self.thumbLayer.borderColor = [[UIColor clearColor] CGColor];
303-
self.thumbLayer.borderWidth = 0.0;
304-
self.thumbLayer.cornerRadius = 0.0;
305-
self.thumbLayer.allowsEdgeAntialiasing = NO;
306-
break;
307-
308-
case ComponentStyleInvisible:
309-
self.thumbLayer.backgroundColor = [[UIColor clearColor] CGColor];
310-
self.thumbLayer.cornerRadius = 0.0;
311-
break;
312-
313-
case ComponentStyleIOS:
314-
default:
315-
self.thumbLayer.backgroundColor = [[UIColor whiteColor] CGColor];
316-
self.thumbLayer.borderColor = [[UIColor colorWithHue:0 saturation: 0 brightness: 0.8 alpha: 1]
317-
CGColor];
318-
self.thumbLayer.borderWidth = 0.5;
319-
self.thumbLayer.cornerRadius = self.thumbLayer.frame.size.width/2;
320-
self.thumbLayer.allowsEdgeAntialiasing = YES;
321-
break;
322-
}
323-
324-
// Shadow
325-
if(shadowRadius != 0.0) {
270+
if( self.value >= self.minimumValue) { // Feature: hide the thumb when below range
271+
const CGSize thumbSizeForStyle = [self thumbSizeIncludingShadow];
272+
const CGFloat thumbWidth = thumbSizeForStyle.width;
273+
const CGFloat thumbHeight = thumbSizeForStyle.height;
274+
const CGRect rectangle = CGRectMake(self.thumbAbscisse - (thumbWidth / 2),
275+
(self.frame.size.height - thumbHeight)/2,
276+
thumbWidth,
277+
thumbHeight);
278+
279+
const CGFloat shadowRadius = ((self.thumbStyle == ComponentStyleIOS)
280+
? iOSThumbShadowRadius
281+
: self.thumbShadowRadius);
282+
const CGSize shadowOffset = ((self.thumbStyle == ComponentStyleIOS)
283+
? iosThumbShadowOffset
284+
: self.thumbShadowOffset);
285+
286+
self.thumbLayer.frame = ((shadowRadius != 0.0) // Ignore offset if there is no shadow
287+
? CGRectInset(rectangle,
288+
shadowRadius + shadowOffset.width,
289+
shadowRadius + shadowOffset.height)
290+
: CGRectInset(rectangle, shadowRadius, shadowRadius));
291+
292+
switch(self.thumbStyle) {
293+
case ComponentStyleRounded: // A rounded thumb is circular
294+
self.thumbLayer.backgroundColor = [self.thumbColor CGColor];
295+
self.thumbLayer.borderColor = [[UIColor clearColor] CGColor];
296+
self.thumbLayer.borderWidth = 0.0;
297+
self.thumbLayer.cornerRadius = self.thumbLayer.frame.size.width/2;
298+
self.thumbLayer.allowsEdgeAntialiasing = YES;
299+
break;
300+
301+
case ComponentStyleRectangular:
302+
self.thumbLayer.backgroundColor = [self.thumbColor CGColor];
303+
self.thumbLayer.borderColor = [[UIColor clearColor] CGColor];
304+
self.thumbLayer.borderWidth = 0.0;
305+
self.thumbLayer.cornerRadius = 0.0;
306+
self.thumbLayer.allowsEdgeAntialiasing = NO;
307+
break;
308+
309+
case ComponentStyleInvisible:
310+
self.thumbLayer.backgroundColor = [[UIColor clearColor] CGColor];
311+
self.thumbLayer.cornerRadius = 0.0;
312+
break;
313+
314+
case ComponentStyleIOS:
315+
default:
316+
self.thumbLayer.backgroundColor = [[UIColor whiteColor] CGColor];
317+
self.thumbLayer.borderColor = [[UIColor colorWithHue:0 saturation: 0 brightness: 0.8 alpha: 1]
318+
CGColor];
319+
self.thumbLayer.borderWidth = 0.5;
320+
self.thumbLayer.cornerRadius = self.thumbLayer.frame.size.width/2;
321+
self.thumbLayer.allowsEdgeAntialiasing = YES;
322+
break;
323+
}
324+
325+
// Shadow
326+
if(shadowRadius != 0.0) {
326327
#if TARGET_INTERFACE_BUILDER
327-
self.thumbLayer.shadowOffset = CGSizeMake(shadowOffset.width, -shadowOffset.height);
328+
self.thumbLayer.shadowOffset = CGSizeMake(shadowOffset.width, -shadowOffset.height);
328329
#else // !TARGET_INTERFACE_BUILDER
329-
self.thumbLayer.shadowOffset = shadowOffset;
330+
self.thumbLayer.shadowOffset = shadowOffset;
330331
#endif // TARGET_INTERFACE_BUILDER
331-
332-
self.thumbLayer.shadowRadius = shadowRadius;
333-
self.thumbLayer.shadowColor = [[UIColor blackColor] CGColor];
334-
self.thumbLayer.shadowOpacity = 0.15;
335-
} else {
336-
self.thumbLayer.shadowRadius = 0.0;
337-
self.thumbLayer.shadowOffset = CGSizeZero;
338-
self.thumbLayer.shadowColor = [[UIColor clearColor] CGColor];
339-
self.thumbLayer.shadowOpacity = 0.0;
332+
333+
self.thumbLayer.shadowRadius = shadowRadius;
334+
self.thumbLayer.shadowColor = [[UIColor blackColor] CGColor];
335+
self.thumbLayer.shadowOpacity = 0.15;
336+
} else {
337+
self.thumbLayer.shadowRadius = 0.0;
338+
self.thumbLayer.shadowOffset = CGSizeZero;
339+
self.thumbLayer.shadowColor = [[UIColor clearColor] CGColor];
340+
self.thumbLayer.shadowOpacity = 0.0;
341+
}
340342
}
341343
}
342344

0 commit comments

Comments
 (0)