diff --git a/NMRangeSlider-Demo/Images/revealed-track.png b/NMRangeSlider-Demo/Images/revealed-track.png new file mode 100644 index 0000000..45f8e92 Binary files /dev/null and b/NMRangeSlider-Demo/Images/revealed-track.png differ diff --git a/NMRangeSlider-Demo/Images/revealed-track@2x.png b/NMRangeSlider-Demo/Images/revealed-track@2x.png new file mode 100644 index 0000000..f4a830d Binary files /dev/null and b/NMRangeSlider-Demo/Images/revealed-track@2x.png differ diff --git a/NMRangeSlider-Demo/NMDemoTVC.h b/NMRangeSlider-Demo/NMDemoTVC.h index c853a5d..24b62aa 100644 --- a/NMRangeSlider-Demo/NMDemoTVC.h +++ b/NMRangeSlider-Demo/NMDemoTVC.h @@ -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; diff --git a/NMRangeSlider-Demo/NMDemoTVC.m b/NMRangeSlider-Demo/NMDemoTVC.m index 2fddf49..06d31ee 100644 --- a/NMRangeSlider-Demo/NMDemoTVC.m +++ b/NMRangeSlider-Demo/NMDemoTVC.m @@ -32,6 +32,7 @@ - (void)viewDidLoad [self configureSteppedSlider]; [self configureSteppedSliderAlternative]; [self configureCrossOverSlider]; + [self configureRevealedSlider]; [self configureProgramically]; } @@ -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; +} // ------------------------------------------------------------------------------------------------------ diff --git a/NMRangeSlider-Demo/en.lproj/MainStoryboard.storyboard b/NMRangeSlider-Demo/en.lproj/MainStoryboard.storyboard index 311646c..b340955 100644 --- a/NMRangeSlider-Demo/en.lproj/MainStoryboard.storyboard +++ b/NMRangeSlider-Demo/en.lproj/MainStoryboard.storyboard @@ -1,8 +1,8 @@ - + - + @@ -336,10 +336,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -356,7 +392,7 @@ - + @@ -391,6 +427,7 @@ + diff --git a/NMRangeSlider.xcodeproj/project.pbxproj b/NMRangeSlider.xcodeproj/project.pbxproj index ca5a464..b659dbb 100644 --- a/NMRangeSlider.xcodeproj/project.pbxproj +++ b/NMRangeSlider.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + E2F6E99F183A151000518E9A /* revealed-track.png in Resources */ = {isa = PBXBuildFile; fileRef = E2F6E99E183A151000518E9A /* revealed-track.png */; }; + E2F6E9A1183A158100518E9A /* revealed-track@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = E2F6E9A0183A158100518E9A /* revealed-track@2x.png */; }; 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 */; }; @@ -57,6 +59,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + E2F6E99E183A151000518E9A /* revealed-track.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "revealed-track.png"; sourceTree = ""; }; + E2F6E9A0183A158100518E9A /* revealed-track@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "revealed-track@2x.png"; sourceTree = ""; }; 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; }; @@ -243,6 +247,8 @@ EC36F9D015CE3590009A1A04 /* Icon@2x.png */, EC36F99C15CE0955009A1A04 /* navbar-nullmonkey-title.png */, EC36F99D15CE0955009A1A04 /* navbar-nullmonkey-title@2x.png */, + E2F6E99E183A151000518E9A /* revealed-track.png */, + E2F6E9A0183A158100518E9A /* revealed-track@2x.png */, ); path = Images; sourceTree = ""; @@ -330,6 +336,7 @@ EC6CCCC1180690AE00FBE743 /* slider-default7-trackBackground@2x.png in Resources */, EC36F97215CD0D53009A1A04 /* slider-default-handle-highlighted@2x.png in Resources */, EC4B675C17F8F1470054842C /* Default-568h@2x.png in Resources */, + E2F6E9A1183A158100518E9A /* revealed-track@2x.png in Resources */, EC36F97315CD0D53009A1A04 /* slider-default-handle.png in Resources */, EC36F97415CD0D53009A1A04 /* slider-default-handle@2x.png in Resources */, EC36F97515CD0D53009A1A04 /* slider-default-track.png in Resources */, @@ -339,6 +346,7 @@ EC36F97815CD0D53009A1A04 /* slider-default_trackBackground@2x.png in Resources */, EC36F99E15CE0955009A1A04 /* navbar-nullmonkey-title.png in Resources */, EC36F99F15CE0955009A1A04 /* navbar-nullmonkey-title@2x.png in Resources */, + E2F6E99F183A151000518E9A /* revealed-track.png in Resources */, EC6CCCC7180690AE00FBE743 /* slider-default7-handle@2x.png in Resources */, EC36F9A615CE1295009A1A04 /* README.md in Resources */, EC4B675A17F8EDAA0054842C /* slider-default-trackCrossedOver@2x.png in Resources */, diff --git a/NMRangeSlider/NMRangeSlider.h b/NMRangeSlider/NMRangeSlider.h index e2fc0fc..0dcf753 100755 --- a/NMRangeSlider/NMRangeSlider.h +++ b/NMRangeSlider/NMRangeSlider.h @@ -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; diff --git a/NMRangeSlider/NMRangeSlider.m b/NMRangeSlider/NMRangeSlider.m index da0e597..94fc5db 100755 --- a/NMRangeSlider/NMRangeSlider.m +++ b/NMRangeSlider/NMRangeSlider.m @@ -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); @@ -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 {