Skip to content

Commit

Permalink
Send UIControlEventValueChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncooke committed Apr 12, 2017
1 parent ea0d27f commit 9731fa7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
10 changes: 6 additions & 4 deletions Example/RangeSliderDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ @interface ViewController ()

@implementation ViewController

- (void)logControlEvent:(TTRangeSlider *)sender {
NSLog(@"Standard slider updated. Min Value: %.0f Max Value: %.0f", sender.selectedMinimum, sender.selectedMaximum);
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Expand All @@ -26,6 +30,7 @@ - (void)viewDidLoad {
self.rangeSlider.maxValue = 200;
self.rangeSlider.selectedMinimum = 50;
self.rangeSlider.selectedMaximum = 150;
[self.rangeSlider addTarget:self action:@selector(logControlEvent:) forControlEvents:UIControlEventValueChanged];

//currency range slider
self.rangeSliderCurrency.delegate = self;
Expand Down Expand Up @@ -62,10 +67,7 @@ - (void)didReceiveMemoryWarning {

#pragma mark TTRangeSliderViewDelegate
-(void)rangeSlider:(TTRangeSlider *)sender didChangeSelectedMinimumValue:(float)selectedMinimum andMaximumValue:(float)selectedMaximum{
if (sender == self.rangeSlider){
NSLog(@"Standard slider updated. Min Value: %.0f Max Value: %.0f", selectedMinimum, selectedMaximum);
}
else if (sender == self.rangeSliderCurrency) {
if (sender == self.rangeSliderCurrency) {
NSLog(@"Currency slider updated. Min Value: %.0f Max Value: %.0f", selectedMinimum, selectedMaximum);
}
else if (sender == self.rangeSliderCustom){
Expand Down
3 changes: 3 additions & 0 deletions Pod/Classes/TTRangeSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
IB_DESIGNABLE
@interface TTRangeSlider : UIControl <UIGestureRecognizerDelegate>

/**
* Optional delegate.
*/
@property (nonatomic, weak) IBOutlet id<TTRangeSliderDelegate> delegate;

/**
Expand Down
6 changes: 5 additions & 1 deletion Pod/Classes/TTRangeSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,13 @@ - (void)refresh {
[self updateAccessibilityElements];

//update the delegate
if (self.delegate && (self.leftHandleSelected || self.rightHandleSelected)){
if ([self.delegate respondsToSelector:@selector(rangeSlider:didChangeSelectedMinimumValue:andMaximumValue:)] &&
(self.leftHandleSelected || self.rightHandleSelected)){

[self.delegate rangeSlider:self didChangeSelectedMinimumValue:self.selectedMinimum andMaximumValue:self.selectedMaximum];
}

[self sendActionsForControlEvents:UIControlEventValueChanged];
}

- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
Expand Down
4 changes: 2 additions & 2 deletions Pod/Classes/TTRangeSliderDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

@protocol TTRangeSliderDelegate <NSObject>

@optional

/**
* Called when the RangeSlider values are changed
*/
-(void)rangeSlider:(TTRangeSlider *)sender didChangeSelectedMinimumValue:(float)selectedMinimum andMaximumValue:(float)selectedMaximum;

@optional

/**
* Called when the user has finished interacting with the RangeSlider
*/
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ The default slider ranges from 0->100 and has 10 preselected as the minimum, and

Values that the user has selected are exposed using the `selectedMinimum` and `selectedMaximum` properties. You can also use these properties to change the selected values programatically if you wish.

## Getting updates

To be notified when the slider’s value changes, register your action method with the `UIControlEventValueChanged` event. At runtime, the slider calls your method in response to the user changing the slider’s value.

Alternatively you can implement the `TTRangeSliderDelegate` protocol and respond to changes in the `rangeSlider:didChangeSelectedMinimumValue:andMaximumValue:` method.

Other customisation of the control is done using the following properties:
#### `tintColor`
The tintColor property (which you can also set in Interface Builder) sets the overall colour of the control, including the colour of the line, the two handles, and the labels.
Expand Down

0 comments on commit 9731fa7

Please sign in to comment.