Skip to content

Code cleanup and support for ARC for the range slider control. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions RangeSlider/RangeSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,10 @@

#import <UIKit/UIKit.h>

@interface RangeSlider : UIControl{
float minimumValue;
float maximumValue;
float minimumRange;
float selectedMinimumValue;
float selectedMaximumValue;
float distanceFromCenter;

float _padding;

BOOL _maxThumbOn;
BOOL _minThumbOn;

UIImageView * _minThumb;
UIImageView * _maxThumb;
UIImageView * _track;
UIImageView * _trackBackground;
}

@property(nonatomic) float minimumValue;
@property(nonatomic) float maximumValue;
@property(nonatomic) float minimumRange;
@property(nonatomic) float selectedMinimumValue;
@property(nonatomic) float selectedMaximumValue;

@interface RangeSlider : UIControl
@property(nonatomic, readwrite) float minimumValue;
@property(nonatomic, readwrite) float maximumValue;
@property(nonatomic, readwrite) float minimumRange;
@property(nonatomic, readwrite) float selectedMinimumValue;
@property(nonatomic, readwrite) float selectedMaximumValue;
@end
34 changes: 25 additions & 9 deletions RangeSlider/RangeSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,27 @@

#import "RangeSlider.h"

@interface RangeSlider (PrivateMethods)
-(float)xForValue:(float)value;
-(float)valueForX:(float)x;
-(void)updateTrackHighlight;
@interface RangeSlider () {
float minimumValue;
float maximumValue;
float minimumRange;
float selectedMinimumValue;
float selectedMaximumValue;
float distanceFromCenter;

float _padding;

BOOL _maxThumbOn;
BOOL _minThumbOn;

UIImageView * _minThumb;
UIImageView * _maxThumb;
UIImageView * _track;
UIImageView * _trackBackground;
}
- (float) xForValue:(float)value;
- (float) valueForX:(float)x;
- (void) updateTrackHighlight;
@end

@implementation RangeSlider
Expand All @@ -26,20 +43,20 @@ - (id)initWithFrame:(CGRect)frame
_maxThumbOn = false;
_padding = 20;

_trackBackground = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar-background.png"]] autorelease];
_trackBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar-background.png"]];
_trackBackground.center = self.center;
[self addSubview:_trackBackground];

_track = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar-highlight.png"]] autorelease];
_track = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar-highlight.png"]];
_track.center = self.center;
[self addSubview:_track];

_minThumb = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"handle.png"] highlightedImage:[UIImage imageNamed:@"handle-hover.png"]] autorelease];
_minThumb = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"handle.png"] highlightedImage:[UIImage imageNamed:@"handle-hover.png"]];
_minThumb.frame = CGRectMake(0,0, self.frame.size.height,self.frame.size.height);
_minThumb.contentMode = UIViewContentModeCenter;
[self addSubview:_minThumb];

_maxThumb = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"handle.png"] highlightedImage:[UIImage imageNamed:@"handle-hover.png"]] autorelease];
_maxThumb = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"handle.png"] highlightedImage:[UIImage imageNamed:@"handle-hover.png"]];
_maxThumb.frame = CGRectMake(0,0, self.frame.size.height,self.frame.size.height);
_maxThumb.contentMode = UIViewContentModeCenter;
[self addSubview:_maxThumb];
Expand All @@ -48,7 +65,6 @@ - (id)initWithFrame:(CGRect)frame
return self;
}


-(void)layoutSubviews
{
// Set the initial state
Expand Down
22 changes: 11 additions & 11 deletions RangeSlider/RootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}


// Configure the cell.
RangeSlider *slider= [[RangeSlider alloc] initWithFrame:cell.bounds];
slider.minimumValue = 1;
slider.selectedMinimumValue = 2;
slider.maximumValue = 10;
slider.selectedMaximumValue = 8;
slider.minimumRange = 2;
[slider addTarget:self action:@selector(updateRangeLabel:) forControlEvents:UIControlEventValueChanged];

[cell addSubview:slider];
// Configure the cell.
RangeSlider *slider= [[RangeSlider alloc] initWithFrame:cell.bounds];
slider.minimumValue = 1;
slider.selectedMinimumValue = 2;
slider.maximumValue = 10;
slider.selectedMaximumValue = 8;
slider.minimumRange = 2;
[slider addTarget:self action:@selector(updateRangeLabel:) forControlEvents:UIControlEventValueChanged];


[cell addSubview:slider];

return cell;
}
Expand Down