@@ -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