1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// ASValueTrackingSlider.h
// ValueTrackingSlider
//
// Created by Alan Skipp on 19/10/2013.
// Copyright (c) 2013 Alan Skipp. All rights reserved.
//
#import <UIKit/UIKit.h>
@protocol ASValueTrackingSliderDelegate;
@protocol ASValueTrackingSliderDataSource;
@interface ASValueTrackingSlider : UISlider
// present the popUpView manually, without touch event.
- (void)showPopUpViewAnimated:(BOOL)animated;
// the popUpView will not hide again until you call 'hidePopUpViewAnimated:'
- (void)hidePopUpViewAnimated:(BOOL)animated;
@property (strong, nonatomic) UIColor *textColor;
// font can not be nil, it must be a valid UIFont
// default is ‘boldSystemFontOfSize:22.0’
@property (strong, nonatomic) UIFont *font;
// setting the value of 'popUpViewColor' overrides 'popUpViewAnimatedColors' and vice versa
// the return value of 'popUpViewColor' is the currently displayed value
// this will vary if 'popUpViewAnimatedColors' is set (see below)
@property (strong, nonatomic) UIColor *popUpViewColor;
// pass an array of 2 or more UIColors to animate the color change as the slider moves
@property (strong, nonatomic) NSArray *popUpViewAnimatedColors;
// the above @property distributes the colors evenly across the slider
// to specify the exact position of colors on the slider scale, pass an NSArray of NSNumbers
- (void)setPopUpViewAnimatedColors:(NSArray *)popUpViewAnimatedColors withPositions:(NSArray *)positions;
// cornerRadius of the popUpView, default is 4.0
@property (nonatomic) CGFloat popUpViewCornerRadius;
// arrow height of the popUpView, default is 13.0
@property (nonatomic) CGFloat popUpViewArrowLength;
// width padding factor of the popUpView, default is 1.15
@property (nonatomic) CGFloat popUpViewWidthPaddingFactor;
// height padding factor of the popUpView, default is 1.1
@property (nonatomic) CGFloat popUpViewHeightPaddingFactor;
// changes the left handside of the UISlider track to match current popUpView color
// the track color alpha is always set to 1.0, even if popUpView color is less than 1.0
@property (nonatomic) BOOL autoAdjustTrackColor; // (default is YES)
// when setting max FractionDigits the min value is automatically set to the same value
// this ensures that the PopUpView frame maintains a consistent width
- (void)setMaxFractionDigitsDisplayed:(NSUInteger)maxDigits;
// take full control of the format dispayed with a custom NSNumberFormatter
@property (copy, nonatomic) NSNumberFormatter *numberFormatter;
// supply entirely customized strings for slider values using the datasource protocol - see below
@property (weak, nonatomic) id<ASValueTrackingSliderDataSource> dataSource;
// delegate is only needed when used with a TableView or CollectionView - see below
@property (weak, nonatomic) id<ASValueTrackingSliderDelegate> delegate;
@end
// to supply custom text to the popUpView label, implement <ASValueTrackingSliderDataSource>
// the dataSource will be messaged each time the slider value changes
@protocol ASValueTrackingSliderDataSource <NSObject>
- (NSString *)slider:(ASValueTrackingSlider *)slider stringForValue:(float)value;
@end
// when embedding an ASValueTrackingSlider inside a TableView or CollectionView
// you need to ensure that the cell it resides in is brought to the front of the view hierarchy
// to prevent the popUpView from being obscured
@protocol ASValueTrackingSliderDelegate <NSObject>
- (void)sliderWillDisplayPopUpView:(ASValueTrackingSlider *)slider;
@optional
- (void)sliderWillHidePopUpView:(ASValueTrackingSlider *)slider;
- (void)sliderDidHidePopUpView:(ASValueTrackingSlider *)slider;
@end
/*
// the recommended technique for use with a tableView is to create a UITableViewCell subclass ↓
@interface SliderCell : UITableViewCell <ASValueTrackingSliderDelegate>
@property (weak, nonatomic) IBOutlet ASValueTrackingSlider *slider;
@end
@implementation SliderCell
- (void)awakeFromNib
{
self.slider.delegate = self;
}
- (void)sliderWillDisplayPopUpView:(ASValueTrackingSlider *)slider;
{
[self.superview bringSubviewToFront:self];
}
@end
*/