Skip to content
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

Added vertical mode, upper and lower track images, thumb and track dimensions #27

Open
wants to merge 2 commits 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
10 changes: 10 additions & 0 deletions NMRangeSlider-Demo/NMDemoTVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
@property (weak, nonatomic) IBOutlet NMRangeSlider *setValuesSlider;
@property (weak, nonatomic) IBOutlet NMRangeSlider *crossOverSlider;

@property (strong, nonatomic) IBOutlet NMRangeSlider *verticalSlider;


@property (weak, nonatomic) IBOutlet NMRangeSlider *labelSlider;
@property (weak, nonatomic) IBOutlet UILabel *lowerLabel;
@property (weak, nonatomic) IBOutlet UILabel *upperLabel;
Expand All @@ -28,4 +31,11 @@

- (IBAction)labelSliderChanged:(NMRangeSlider*)sender;

#pragma mark - VERTICAL SLIDER
@property (strong, nonatomic) IBOutlet UILabel *rawLowValueLabel;
@property (strong, nonatomic) IBOutlet UILabel *rawUpperValueLabel;
@property (strong, nonatomic) IBOutlet UILabel *convertedLowerValueLabel;
@property (strong, nonatomic) IBOutlet UILabel *convertedUpperValueLabel;
- (IBAction)verticalSliderChanged:(NMRangeSlider *)sender;

@end
106 changes: 106 additions & 0 deletions NMRangeSlider-Demo/NMDemoTVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ - (void)viewDidLoad
[self configureSteppedSliderAlternative];
[self configureCrossOverSlider];
[self configureProgramically];
[self configureVertical];
}


Expand Down Expand Up @@ -71,6 +72,8 @@ - (void) configureStandardSlider
{
self.standardSlider.lowerValue = 0.23;
self.standardSlider.upperValue = 0.53;
self.standardSlider.trackBackgroundWidth = 8.0f;
self.standardSlider.trackWidth = 8.0f;
}


Expand Down Expand Up @@ -142,6 +145,10 @@ - (void) configureLabelSlider
self.labelSlider.upperValue = 100;

self.labelSlider.minimumRange = 10;

self.labelSlider.trackBackgroundWidth = 10.0f;
self.labelSlider.trackWidth = 8.0f;

}

- (void) updateSliderLabels
Expand Down Expand Up @@ -200,12 +207,17 @@ - (void) updateSetValuesSlider
- (void) configureSteppedSlider
{
self.steppedSlider.stepValue = 0.2;
self.steppedSlider.trackBackgroundWidth = 20.0f;
self.steppedSlider.trackWidth = 10.0f;

}

- (void) configureSteppedSliderAlternative
{
self.steppedContinuouslySlider.stepValue = 0.2;
self.steppedContinuouslySlider.stepValueContinuously = YES;
self.steppedContinuouslySlider.trackBackgroundWidth = 20.0f;
self.steppedContinuouslySlider.trackWidth = 10.0f;

}

Expand All @@ -224,6 +236,8 @@ - (void) configureCrossOverSlider

self.crossOverSlider.upperValue = 0.23;
self.crossOverSlider.lowerValue = 0.53;
self.crossOverSlider.trackBackgroundWidth = 6.0f;
self.crossOverSlider.trackWidth = 8.0f;

}

Expand All @@ -238,9 +252,101 @@ - (void) configureProgramically
NMRangeSlider* rangeSlider = [[NMRangeSlider alloc] initWithFrame:CGRectMake(16, 6, 275, 34)];
rangeSlider.lowerValue = 0.54;
rangeSlider.upperValue = 0.94;
rangeSlider.trackWidth = 8.0f;
rangeSlider.trackBackgroundWidth = 10.0f;

[self.programaticallyContainerCell addSubview:rangeSlider];

}

// ------------------------------------------------------------------------------------------------------

#pragma mark -
#pragma mark - Vertical Slider

- (void) configureVerticalThemeForSlider:(NMRangeSlider*) slider
{
UIImage* image = nil;

image = [UIImage imageNamed:@"slider-vertical-trackBackground"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(1.0, 10.0, 1.0, 11.0)];
slider.trackBackgroundImage = image;

image = [UIImage imageNamed:@"slider-vertical-track"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(1.0, 10.0, 1.0, 11.0)];
slider.trackImage = image;

image = [UIImage imageNamed:@"slider-vertical-trackLower"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(1.0, 10.0, 1.0, 11.0)];
slider.lowerTrackImage = image;

image = [UIImage imageNamed:@"slider-vertical-trackUpper"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(1.0, 10.0, 1.0, 11.0)];
slider.upperTrackImage = image;

image = [UIImage imageNamed:@"slider-vertical-handle"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(8.0, 8.0, 8.0, 8.0)];
slider.lowerHandleImageNormal = image;
slider.upperHandleImageNormal = image;

image = [UIImage imageNamed:@"slider-vertical-handle-highlighted"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(8.0, 8.0, 8.0, 8.0)];
slider.lowerHandleImageHighlighted = image;
slider.upperHandleImageHighlighted = image;
}


- (void) configureVertical
{
[self configureVerticalThemeForSlider:self.verticalSlider];

self.verticalSlider.lowerValue = 0.25;
self.verticalSlider.upperValue = 0.75;
self.verticalSlider.verticalMode = YES;

// this enables crossover
// self.verticalSlider.minimumRange = -1.0;

// set the track+background width
self.verticalSlider.trackWidth = 28.0f;
self.verticalSlider.trackBackgroundWidth = 30.0f;

// set the padding at the end of the track.
self.verticalSlider.trackEndPadding = 5.0f;
self.verticalSlider.trackBackgroundEndPadding = 5.0f;

// adjust the handle
self.verticalSlider.handleHeight = 15.0f;
self.verticalSlider.handleWidth = 32.0f;

[self verticalSliderChanged:self.verticalSlider];

}


- (IBAction)verticalSliderChanged:(NMRangeSlider *)sender {

/*
When the slider is in vertical mode it is technically rendered upsidedown (top-left is 0,0). This means the top most handle
represents the "lower" value and sliding it up moves the value toward 0. The opposite is true for the other handle. To compensate
just convert the raw value like below. We will likely fix this later
*/

// raw values
self.rawLowValueLabel.text = [NSString stringWithFormat:@"lower: %f", sender.lowerValue];
self.rawUpperValueLabel.text = [NSString stringWithFormat:@"upper: %f", sender.upperValue];

// convert values - reverse and subtract form the max
self.convertedLowerValueLabel.text = [NSString stringWithFormat:@"lower: %f", sender.maximumValue-sender.upperValue];
self.convertedUpperValueLabel.text = [NSString stringWithFormat:@"upper: %f", sender.maximumValue-sender.lowerValue];

[self.rawLowValueLabel sizeToFit];
[self.rawUpperValueLabel sizeToFit];
[self.convertedLowerValueLabel sizeToFit];
[self.convertedUpperValueLabel sizeToFit];
}


// ------------------------------------------------------------------------------------------------------

#pragma mark -
Expand Down
87 changes: 84 additions & 3 deletions NMRangeSlider-Demo/en.lproj/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="4510" systemVersion="12F45" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="COa-Gf-kKZ">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13C1021" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="COa-Gf-kKZ">
<dependencies>
<deployment defaultVersion="1296" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3742"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<scenes>
<!--DemoTVC-->
Expand Down Expand Up @@ -365,6 +365,82 @@
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection id="xkR-1d-0eZ">
<cells>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="xY9-pe-OgZ" style="IBUITableViewCellStyleDefault" id="Mxv-FS-pxW">
<rect key="frame" x="0.0" y="1168" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Mxv-FS-pxW" id="wra-rb-umN">
<rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Vertical + Lower/Upper Track Image" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="xY9-pe-OgZ">
<rect key="frame" x="15" y="0.0" width="290" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" rowHeight="300" id="WeS-LB-6BM">
<rect key="frame" x="0.0" y="1212" width="320" height="300"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="WeS-LB-6BM" id="OzA-ms-IKH">
<rect key="frame" x="0.0" y="0.0" width="320" height="299"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" id="bIW-6c-tDo" customClass="NMRangeSlider">
<rect key="frame" x="22" y="5" width="52" height="275"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="verticalSliderChanged:" destination="lKo-U9-UYs" eventType="valueChanged" id="Wuw-mM-vhL"/>
</connections>
</view>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Raw Values:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Ka8-6r-iZj">
<rect key="frame" x="154" y="20" width="94" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Converted Values:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="26P-V0-21h">
<rect key="frame" x="108" y="119" width="140" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="lower: 34" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="yHL-Ea-8ff">
<rect key="frame" x="177" y="49" width="71" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="upper: 34" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="tIV-5y-Rdg">
<rect key="frame" x="174" y="78" width="74" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="lower: 34" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="fQg-Yq-2ko">
<rect key="frame" x="177" y="148" width="71" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="upper: 34" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Prb-Vg-qrd">
<rect key="frame" x="174" y="177" width="74" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="lKo-U9-UYs" id="5NJ-PA-88u"/>
Expand All @@ -386,17 +462,22 @@
</view>
</navigationItem>
<connections>
<outlet property="convertedLowerValueLabel" destination="fQg-Yq-2ko" id="Cvs-GL-svz"/>
<outlet property="convertedUpperValueLabel" destination="Prb-Vg-qrd" id="pYQ-NS-tpq"/>
<outlet property="crossOverSlider" destination="ttW-BM-a9a" id="upQ-r6-M1y"/>
<outlet property="labelSlider" destination="LaU-9x-AZw" id="M8C-5R-5wH"/>
<outlet property="lowerLabel" destination="Ojw-yC-dJd" id="ccz-Fg-5Nx"/>
<outlet property="metalSlider" destination="nw3-P9-TiR" id="IFR-G5-mOl"/>
<outlet property="programaticallyContainerCell" destination="2pc-u1-1wl" id="zX8-Cx-gJo"/>
<outlet property="rawLowValueLabel" destination="yHL-Ea-8ff" id="NgA-Ln-CxI"/>
<outlet property="rawUpperValueLabel" destination="tIV-5y-Rdg" id="0dT-nj-3ts"/>
<outlet property="setValuesSlider" destination="OdM-tn-o1x" id="wgM-R7-lm7"/>
<outlet property="singleThumbSlider" destination="qrN-O3-hFu" id="H7w-Gd-dX3"/>
<outlet property="standardSlider" destination="feo-qw-TfS" id="Ejh-Dv-iVT"/>
<outlet property="steppedContinuouslySlider" destination="kNU-cH-scq" id="SvL-9c-azU"/>
<outlet property="steppedSlider" destination="DjS-dB-nvq" id="OPF-iT-8nt"/>
<outlet property="upperLabel" destination="fzv-24-dfp" id="Wc1-Jt-c2R"/>
<outlet property="verticalSlider" destination="bIW-6c-tDo" id="yQe-Qd-uZo"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="M4v-jO-gTj" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -431,4 +512,4 @@
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
</document>
</document>
Loading