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

Revealed track image feature #15

Open
wants to merge 7 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
Binary file added NMRangeSlider-Demo/Images/revealed-track.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added NMRangeSlider-Demo/Images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions NMRangeSlider-Demo/NMDemoTVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@property (weak, nonatomic) IBOutlet NMRangeSlider *steppedContinuouslySlider;
@property (weak, nonatomic) IBOutlet NMRangeSlider *setValuesSlider;
@property (weak, nonatomic) IBOutlet NMRangeSlider *crossOverSlider;
@property (weak, nonatomic) IBOutlet NMRangeSlider *revealedTrackSlider;

@property (weak, nonatomic) IBOutlet NMRangeSlider *labelSlider;
@property (weak, nonatomic) IBOutlet UILabel *lowerLabel;
Expand Down
12 changes: 12 additions & 0 deletions NMRangeSlider-Demo/NMDemoTVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ - (void)viewDidLoad
[self configureSteppedSlider];
[self configureSteppedSliderAlternative];
[self configureCrossOverSlider];
[self configureRevealedSlider];
[self configureProgramically];
}

Expand Down Expand Up @@ -227,6 +228,17 @@ - (void) configureCrossOverSlider

}

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

#pragma mark -
#pragma mark - Revealed Track Slider

- (void) configureRevealedSlider
{
self.revealedTrackSlider.revealedTrackImage = [UIImage imageNamed:@"revealed-track"];
self.revealedTrackSlider.lowerValue = 0.2;
self.revealedTrackSlider.upperValue = 0.8;
}

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

Expand Down
45 changes: 41 additions & 4 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="4514" systemVersion="13A603" 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="3747"/>
</dependencies>
<scenes>
<!--DemoTVC-->
Expand Down Expand Up @@ -336,10 +336,46 @@
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection id="IOq-4k-49n">
<cells>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="Agd-mX-hJc" style="IBUITableViewCellStyleDefault" id="fEp-qo-uFX">
<rect key="frame" x="0.0" y="1060" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="fEp-qo-uFX" id="uvU-G9-zUZ">
<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="Revealed-Track" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Agd-mX-hJc">
<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" id="DNy-8R-RPf">
<rect key="frame" x="0.0" y="1104" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="DNy-8R-RPf" id="Olf-5J-Vju">
<rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" id="GV7-I4-RT7" customClass="NMRangeSlider">
<rect key="frame" x="13" y="6" width="275" height="34"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="tableCellGroupedBackgroundColor"/>
</view>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection id="Ici-Pw-1YI">
<cells>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="h1S-mP-jdr" style="IBUITableViewCellStyleDefault" id="DjD-BM-lMj">
<rect key="frame" x="0.0" y="1060" width="320" height="44"/>
<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="DjD-BM-lMj" id="vq5-1o-ccg">
<rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
Expand All @@ -356,7 +392,7 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="2pc-u1-1wl">
<rect key="frame" x="0.0" y="1104" width="320" height="44"/>
<rect key="frame" x="0.0" y="1212" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="2pc-u1-1wl" id="7Os-LN-Mf1">
<rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
Expand Down Expand Up @@ -391,6 +427,7 @@
<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="revealedTrackSlider" destination="GV7-I4-RT7" id="n0h-Ve-Ur0"/>
<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"/>
Expand Down
8 changes: 8 additions & 0 deletions NMRangeSlider.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
E2F6E99F183A151000518E9A /* revealed-track.png in Resources */ = {isa = PBXBuildFile; fileRef = E2F6E99E183A151000518E9A /* revealed-track.png */; };
E2F6E9A1183A158100518E9A /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = E2F6E9A0183A158100518E9A /* [email protected] */; };
EC36F93715CD0B96009A1A04 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EC36F93615CD0B96009A1A04 /* UIKit.framework */; };
EC36F93915CD0B96009A1A04 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EC36F93815CD0B96009A1A04 /* Foundation.framework */; };
EC36F93B15CD0B96009A1A04 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EC36F93A15CD0B96009A1A04 /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -57,6 +59,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
E2F6E99E183A151000518E9A /* revealed-track.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "revealed-track.png"; sourceTree = "<group>"; };
E2F6E9A0183A158100518E9A /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
EC36F93215CD0B96009A1A04 /* NMRangeSlider.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NMRangeSlider.app; sourceTree = BUILT_PRODUCTS_DIR; };
EC36F93615CD0B96009A1A04 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
EC36F93815CD0B96009A1A04 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -243,6 +247,8 @@
EC36F9D015CE3590009A1A04 /* [email protected] */,
EC36F99C15CE0955009A1A04 /* navbar-nullmonkey-title.png */,
EC36F99D15CE0955009A1A04 /* [email protected] */,
E2F6E99E183A151000518E9A /* revealed-track.png */,
E2F6E9A0183A158100518E9A /* [email protected] */,
);
path = Images;
sourceTree = "<group>";
Expand Down Expand Up @@ -330,6 +336,7 @@
EC6CCCC1180690AE00FBE743 /* [email protected] in Resources */,
EC36F97215CD0D53009A1A04 /* [email protected] in Resources */,
EC4B675C17F8F1470054842C /* [email protected] in Resources */,
E2F6E9A1183A158100518E9A /* [email protected] in Resources */,
EC36F97315CD0D53009A1A04 /* slider-default-handle.png in Resources */,
EC36F97415CD0D53009A1A04 /* [email protected] in Resources */,
EC36F97515CD0D53009A1A04 /* slider-default-track.png in Resources */,
Expand All @@ -339,6 +346,7 @@
EC36F97815CD0D53009A1A04 /* [email protected] in Resources */,
EC36F99E15CE0955009A1A04 /* navbar-nullmonkey-title.png in Resources */,
EC36F99F15CE0955009A1A04 /* [email protected] in Resources */,
E2F6E99F183A151000518E9A /* revealed-track.png in Resources */,
EC6CCCC7180690AE00FBE743 /* [email protected] in Resources */,
EC36F9A615CE1295009A1A04 /* README.md in Resources */,
EC4B675A17F8EDAA0054842C /* [email protected] in Resources */,
Expand Down
3 changes: 3 additions & 0 deletions NMRangeSlider/NMRangeSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@

@property(retain, nonatomic) UIImage* trackImage;

// Track image that is revealed instead of streached, by default this is null and ignored for backward compatibility.
@property(retain, nonatomic) UIImage* revealedTrackImage;

// track image when lower value is higher than the upper value (eg. when minimum range is negative
@property(retain, nonatomic) UIImage* trackCrossedOverImage;

Expand Down
36 changes: 32 additions & 4 deletions NMRangeSlider/NMRangeSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ - (CGRect)trackRect

float lowerHandleWidth = _lowerHandleHidden ? 2.0f : _lowerHandle.frame.size.width;
float upperHandleWidth = _upperHandleHidden ? 2.0f : _upperHandle.frame.size.width;

float xLowerValue = ((self.bounds.size.width - lowerHandleWidth) * (_lowerValue - _minimumValue) / (_maximumValue - _minimumValue))+(lowerHandleWidth/2.0f);
float xUpperValue = ((self.bounds.size.width - upperHandleWidth) * (_upperValue - _minimumValue) / (_maximumValue - _minimumValue))+(upperHandleWidth/2.0f);

Expand All @@ -427,16 +426,45 @@ - (CGRect)trackRect

- (UIImage*) trackImageForCurrentValues
{
if(self.lowerValue <= self.upperValue)
if (self.revealedTrackImage)
{
return self.trackImage;
return [self revealedTrackImageForCurrentValues];
}
else
{
return self.trackCrossedOverImage;
if(self.lowerValue <= self.upperValue)
{
return self.trackImage;
}
else
{
return self.trackCrossedOverImage;
}
}
}

- (UIImage *) revealedTrackImageForCurrentValues {
//Get left and right x positions
float lowerHandleWidth = _lowerHandleHidden ? 2.0f : _lowerHandle.frame.size.width;
float upperHandleWidth = _upperHandleHidden ? 2.0f : _upperHandle.frame.size.width;
float xLowerValue = ((self.bounds.size.width - lowerHandleWidth) * (_lowerValue - _minimumValue) / (_maximumValue - _minimumValue))+(lowerHandleWidth/2.0f);
float xUpperValue = ((self.bounds.size.width - upperHandleWidth) * (_upperValue - _minimumValue) / (_maximumValue - _minimumValue))+(upperHandleWidth/2.0f);

//Crop the image
CGFloat imageScale = self.revealedTrackImage.scale;
CGRect croppedImageRect = CGRectMake(xLowerValue * imageScale,
0.0f,
(xUpperValue - xLowerValue) * imageScale,
self.revealedTrackImage.size.height * imageScale);
CGImageRef croppedImageRef = CGImageCreateWithImageInRect([self.revealedTrackImage CGImage], croppedImageRect);
UIImage *croppedImage = [UIImage imageWithCGImage:croppedImageRef
scale:imageScale
orientation:self.revealedTrackImage.imageOrientation];
CGImageRelease(croppedImageRef);

return croppedImage;
}

//returns the rect for the background image
-(CGRect) trackBackgroundRect
{
Expand Down