Skip to content

Commit e4e3f09

Browse files
committed
add minValueString, maxValueString
1 parent b0d0b53 commit e4e3f09

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

Demo/RangeSeekSliderDemo/Base.lproj/Main.storyboard

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<real key="value" value="500"/>
125125
</userDefinedRuntimeAttribute>
126126
<userDefinedRuntimeAttribute type="boolean" keyPath="enableStep" value="YES"/>
127+
<userDefinedRuntimeAttribute type="string" keyPath="minValueString" value="Free"/>
127128
</userDefinedRuntimeAttributes>
128129
</view>
129130
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Hidden Labels:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oXk-Mj-BG8">

RangeSeekSlider.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'RangeSeekSlider'
3-
s.version = '1.0.5'
3+
s.version = '1.1.0'
44
s.summary = 'RangeSeedSlider provides a customizable range slider like a UISlider.'
55
s.description = <<-DESC
66
RangeSeedSlider provides a customizable range slider like a UISlider.

Sources/RangeSeekSlider.swift

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ import UIKit
6767
}
6868
}
6969

70+
/// String of the label when the handle is set to the minimum value.
71+
@IBInspectable public var minValueString: String?
72+
73+
/// String of the label when the handle is set to the maximum value.
74+
@IBInspectable public var maxValueString: String?
75+
7076
/// The font of the minimum value text label. If not set, the default is system font size 12.0.
7177
public var minLabelFont: UIFont = UIFont.systemFont(ofSize: 12.0) {
7278
didSet {
@@ -198,7 +204,7 @@ import UIKit
198204
/// Set the slider line height (default 1.0)
199205
@IBInspectable public var lineHeight: CGFloat = 1.0 {
200206
didSet {
201-
setNeedsLayout()
207+
updateLineHeight()
202208
}
203209
}
204210

@@ -281,23 +287,12 @@ import UIKit
281287
open override func layoutSubviews() {
282288
super.layoutSubviews()
283289

284-
// positioning for the slider line
285-
let barSidePadding: CGFloat = 16.0
286-
let currentFrame: CGRect = frame
287-
let yMiddle: CGFloat = currentFrame.height / 2.0
288-
let lineLeftSide: CGPoint = CGPoint(x: barSidePadding, y: yMiddle)
289-
let lineRightSide: CGPoint = CGPoint(x: (currentFrame.width - barSidePadding),
290-
y: yMiddle)
291-
sliderLine.frame = CGRect(x: lineLeftSide.x,
292-
y: lineLeftSide.y,
293-
width: lineRightSide.x - lineLeftSide.x,
294-
height: lineHeight)
295-
296-
sliderLine.cornerRadius = lineHeight / 2.0
297-
298-
updateLabelValues()
299-
updateHandlePositions()
300-
updateLabelPositions()
290+
if !leftHandleSelected && !rightHandleSelected {
291+
updateLineHeight()
292+
updateLabelValues()
293+
updateHandlePositions()
294+
updateLabelPositions()
295+
}
301296
}
302297

303298
open override var intrinsicContentSize: CGSize {
@@ -510,15 +505,37 @@ import UIKit
510505
return sliderLine.frame.minX + offset
511506
}
512507

508+
private func updateLineHeight() {
509+
let barSidePadding: CGFloat = 16.0
510+
let yMiddle: CGFloat = frame.height / 2.0
511+
let lineLeftSide: CGPoint = CGPoint(x: barSidePadding, y: yMiddle)
512+
let lineRightSide: CGPoint = CGPoint(x: frame.width - barSidePadding,
513+
y: yMiddle)
514+
sliderLine.frame = CGRect(x: lineLeftSide.x,
515+
y: lineLeftSide.y,
516+
width: lineRightSide.x - lineLeftSide.x,
517+
height: lineHeight)
518+
sliderLine.cornerRadius = lineHeight / 2.0
519+
}
520+
513521
private func updateLabelValues() {
514522
if hideLabels {
515523
minLabel.string = nil
516524
maxLabel.string = nil
517525
return
518526
}
519527

520-
minLabel.string = numberFormatter.string(from: selectedMinValue as NSNumber)
521-
maxLabel.string = numberFormatter.string(from: selectedMaxValue as NSNumber)
528+
if let minValueString = minValueString, selectedMinValue == minValue {
529+
minLabel.string = minValueString
530+
} else {
531+
minLabel.string = numberFormatter.string(from: selectedMinValue as NSNumber)
532+
}
533+
534+
if let maxValueString = maxValueString, selectedMaxValue == maxValue {
535+
maxLabel.string = maxValueString
536+
} else {
537+
maxLabel.string = numberFormatter.string(from: selectedMaxValue as NSNumber)
538+
}
522539

523540
if let nsstring = minLabel.string as? NSString {
524541
minLabelTextSize = nsstring.size(attributes: [NSFontAttributeName: minLabelFont])

0 commit comments

Comments
 (0)