Skip to content

Commit

Permalink
version 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
thehung111 committed Jan 6, 2017
1 parent e7448a8 commit e98537e
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion NHRangeSlider.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Pod::Spec.new do |s|

s.name = "NHRangeSlider"
s.version = "0.1.1"
s.version = "0.1.2"
s.summary = "A custom range slider in Swift."

s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion NHRangeSlider/NHRangeSlider/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.1.1</string>
<string>0.1.2</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
3 changes: 2 additions & 1 deletion NHRangeSlider/NHRangeSlider/NHRangeSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ open class NHRangeSlider: UIControl {
}
}


/// track highlight tint color
@IBInspectable open var trackHighlightTintColor: UIColor = UIColor(red: 0.0, green: 0.45, blue: 0.94, alpha: 1.0) {
didSet {
Expand Down Expand Up @@ -343,6 +342,8 @@ open class NHRangeSlider: UIControl {
if (bounds.width != bounds.height) {
deltaValue = (maximumValue - minimumValue) * deltaLocation / Double(bounds.width - bounds.height)
}


previouslocation = location

// if both are highlighted. we need to decide which direction to drag
Expand Down
20 changes: 13 additions & 7 deletions NHRangeSlider/NHRangeSlider/NHRangeSliderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public extension NHRangeSliderViewDelegate{
func sliderValueChanged(slider: NHRangeSlider?){}
}

/// Range slider with labels for upper and lower thumbs
/// Range slider with labels for upper and lower thumbs, title label and configurable step value (optional)
open class NHRangeSliderView: UIView {

//MARK: properties
Expand All @@ -48,14 +48,18 @@ open class NHRangeSliderView: UIView {
open var upperLabel : UILabel? = nil

/// display format for lower and upper values. Default to %.0f to display value as Int
open var displayStringFormat: String = "%.0f"
open var displayStringFormat: String = "%.0f" {
didSet {
updateLabelDisplay()
}
}

/// vertical spacing
open var spacing: CGFloat = 4.0

/// position of thumb labels. Set to STICKY to stick to left and right positions. Set to FOLLOW to follow left and right thumbs
open var thumbLabelStyle: NHSliderLabelStyle = .STICKY

/// minimum value
@IBInspectable open var minimumValue: Double = 0.0 {
didSet {
Expand Down Expand Up @@ -218,8 +222,10 @@ open class NHRangeSliderView: UIView {
self.lowerLabel?.text = String(format: self.displayStringFormat, rangeSlider!.lowerValue )
self.upperLabel?.text = String(format: self.displayStringFormat, rangeSlider!.upperValue )

self.setNeedsLayout()
self.layoutIfNeeded()
if self.lowerLabel != nil {
self.setNeedsLayout()
self.layoutIfNeeded()
}
}

/// layout subviews
Expand Down Expand Up @@ -254,8 +260,8 @@ open class NHRangeSliderView: UIView {


if self.thumbLabelStyle == .FOLLOW {
lowerLabelX = rangeSlider.lowerThumbLayer.frame.minX + self.spacing
upperLabelX = rangeSlider.upperThumbLayer.frame.minX + self.spacing
lowerLabelX = rangeSlider.lowerThumbLayer.frame.midX - lowerWidth / 2
upperLabelX = rangeSlider.upperThumbLayer.frame.midX - upperWidth / 2
}
else {
// fix lower label to left and upper label to right
Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
![Swift](http://img.shields.io/badge/swift-3.0-brightgreen.svg)&nbsp;[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)&nbsp;[![CocoaPods](https://img.shields.io/cocoapods/v/NHRangeSlider.svg)](https://github.com/thehung111/NHRangeSlider)


A custom range slider in Swift. Forked from [RangeSlider](https://github.com/warchimede/RangeSlider) with some enhancements.
A custom range slider in Swift. Well-documented with examples. Forked from [RangeSlider](https://github.com/warchimede/RangeSlider) with some enhancements.

<img src="screenshot.png" />

Expand All @@ -24,7 +24,7 @@ platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
pod 'NHRangeSlider', '~> 0.1.1'
pod 'NHRangeSlider', '~> 0.1.2'
end
```

Expand All @@ -39,7 +39,7 @@ $ pod install
Put the following in your Cartfile:

```ogdl
github "thehung111/NHRangeSlider" ~> 0.1.1
github "thehung111/NHRangeSlider" ~> 0.1.2
```

Run `carthage update --platform iOS --no-use-binaries`
Expand Down Expand Up @@ -116,6 +116,24 @@ sliderWithLabelFollowView.sizeToFit()
self.view.addSubview(sliderWithLabelFollowView)
```

### Slider with custom format

```swift
let sliderCustomStringView = NHRangeSliderView(frame: ...)
sliderCustomStringView.trackHighlightTintColor = UIColor.black
sliderCustomStringView.lowerValue = 30.0
sliderCustomStringView.upperValue = 70.0
sliderCustomStringView.gapBetweenThumbs = 5

sliderCustomStringView.thumbLabelStyle = .FOLLOW

sliderCustomStringView.titleLabel?.text = "Slider with custom format"
sliderCustomStringView.displayStringFormat = "Price: $%.1f"
sliderCustomStringView.sizeToFit()
self.view.addSubview(sliderCustomStringView)

```

## Configuration

The range slider view (**NHRangeSliderView**) can be customized and information can be accessed through these properties :
Expand Down
2 changes: 2 additions & 0 deletions SliderExample/SliderExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@
BDBEB3CB1E0660E200FE2D6F /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
BDBEB3CC1E0660E200FE2D6F /* Build configuration list for PBXNativeTarget "SliderExampleTests" */ = {
isa = XCConfigurationList;
Expand All @@ -499,6 +500,7 @@
BDBEB3CE1E0660E200FE2D6F /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
18 changes: 18 additions & 0 deletions SliderExample/SliderExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,29 @@ class ViewController: UIViewController {
sliderWithLabelFollowView.lowerValue = 30.0
sliderWithLabelFollowView.upperValue = 70.0
sliderWithLabelFollowView.gapBetweenThumbs = 5

sliderWithLabelFollowView.thumbLabelStyle = .FOLLOW
sliderWithLabelFollowView.titleLabel?.text = "Slider with labels follow thumbs"
sliderWithLabelFollowView.sizeToFit()
self.view.addSubview(sliderWithLabelFollowView)

// custom string format example
let sliderCustomStringView = NHRangeSliderView(frame: CGRect(x: 16, y: sliderWithLabelFollowView.frame.maxY + 8,
width: sliderView.frame.size.width,
height: sliderView.frame.size.height) )
sliderCustomStringView.trackHighlightTintColor = UIColor.black
sliderCustomStringView.lowerValue = 30.0
sliderCustomStringView.upperValue = 70.0
sliderCustomStringView.gapBetweenThumbs = 5

sliderCustomStringView.thumbLabelStyle = .FOLLOW

sliderCustomStringView.titleLabel?.text = "Slider with custom format"
sliderCustomStringView.displayStringFormat = "Price: $%.1f"
sliderCustomStringView.sizeToFit()
self.view.addSubview(sliderCustomStringView)


}

override func didReceiveMemoryWarning() {
Expand Down

0 comments on commit e98537e

Please sign in to comment.