Skip to content

gurgeous/old_AMDoubleSlider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to AMDoubleSlider

AMDoubleSlider is a two-headed slider similar to UISlider. It looks just like a UISlider, but with two heads. Features:

  • similar to UISlider
  • displays a label above each handle
  • the labels never overlap and the handles never cross
  • can round to discrete values

AMDoubleSlider is an extraction from Dwellable.

Screenshot

Install

Add AMDoubleSlider.h, AMDoubleSlider.m and AMDoubleSlider.bundle to your project.

Example Usage

Check out AppDelegate.m in the Demo app. In the meantime, here's an example:

NSArray *data = @[ @"XS", @"S", @"M", @"L", @"XL", @"XXL" ];
AMDoubleSlider *sizes = [[AMDoubleSlider alloc] initWithFrame:CGRectMake(0, 0, 240, 60)];
sizes.boundsMin = 0;
sizes.boundsMax = data.count - 1;
sizes.labeler = ^NSString *(float value) {
    return data[(int)value];
};
sizes.rounder = ^(float value) {
    return roundf(value);
};

Details

Min and Max

The moving part of the slider is called the "handle". AMDoubleSlider has two handles, naturally. The value of each handle is a float between boundsMin and boundsMax. The left handle is called min and the right handle is called max.

Rounding

Min and max are always floats, though often you want discrete values. For example, you might want to pick values between one and ten, or t-shirt sizes, etc. To map from floats to discrete values, specify a rounder block. If you specify a rounder, min and max will always be rounded when you access them. Examples:

// round to nearest ints
slider.rounder = ^(float value) {
    return roundf(value);
};

// multiples of fifty
slider.rounder = ^(float value) {
    return roundf(value / 50) * 50;
};

Labeling

AMDoubleSlider draws a label above each handle so the user knows what's happening. Use the labeler property to map from values to labels. Note that the value passed into labeler is always rounded (via rounder) first. Examples:

// currency
slider.labeler = ^NSString *(float value) {
    return [NSString stringWithFormat:@"$%d", (int)value];
};

// show decimals
slider.labeler = ^NSString *(float value) {
    return [NSString stringWithFormat:@"%.1f", value];
};

// lookup from an array
slider.labeler = ^NSString *(float value) {
    return mylabels[(int)value];
};

About

A double-headed slider for iOS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published