Skip to content

Commit d7a18c6

Browse files
committed
Setup demo of programmatic knob values change + increased framework version ✨
1 parent c9951f2 commit d7a18c6

File tree

5 files changed

+85
-27
lines changed

5 files changed

+85
-27
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Change Log
22
All changes to RangeUISlider will be documented in this file.
33

4+
## [1.12.0](https://github.com/chicio/RangeUISlider/releases/tag/1.12.0)
5+
Release date: 2020-10-09.
6+
7+
#### Added
8+
- Programmatic api to change the knob values
9+
- Now Minimum iOS version is 9.0
10+
- Github Actions as CI
11+
412
## [1.11.0](https://github.com/chicio/RangeUISlider/releases/tag/1.11.0)
513
Release date: 2019-09-24.
614

Demo/ChangeProgrammaticViewController.swift

+24-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ChangeProgrammaticViewController: UIViewController, RangeUISliderDelegate
1919
rangeSlider.delegate = self
2020
rangeSlider.scaleMinValue = 0 //If you don't set any value the default is 0
2121
rangeSlider.scaleMaxValue = 100 //If you don't set any value the default is 1
22-
rangeSlider.defaultValueLeftKnob = 5 //If the scale is the default one insert a value between 0 and 1
22+
rangeSlider.defaultValueLeftKnob = 10 //If the scale is the default one insert a value between 0 and 1
2323
rangeSlider.defaultValueRightKnob = 75 //If the scale is the default one insert a value between 0 and 1
2424
rangeSlider.rangeSelectedGradientColor1 = #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)
2525
rangeSlider.rangeSelectedGradientColor2 = #colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1)
@@ -73,14 +73,33 @@ class ChangeProgrammaticViewController: UIViewController, RangeUISliderDelegate
7373
constant: 50)
7474
])
7575

76-
self.rangeSlider.changeLeftKnobPosition(position: 35.0)
77-
self.rangeSlider.changeRightKnobPosition(position: 75.0)
76+
self.rangeSlider.changeLeftKnob(value: 35.0)
77+
self.rangeSlider.changeRightKnob(value: 75.0)
7878

7979
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
80-
self.rangeSlider.changeLeftKnobPosition(position: 45.0)
80+
self.rangeSlider.changeLeftKnob(value: 45.0)
8181
}
82+
83+
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
84+
//Invalid left values
85+
self.rangeSlider.changeLeftKnob(value: -45.0)
86+
self.rangeSlider.changeLeftKnob(value: 78.0)
87+
}
88+
8289
DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
83-
self.rangeSlider.changeRightKnobPosition(position: 90.0)
90+
self.rangeSlider.changeRightKnob(value: 90.0)
91+
}
92+
93+
DispatchQueue.main.asyncAfter(deadline: .now() + 6) {
94+
//Invalid right values
95+
self.rangeSlider.changeRightKnob(value: 10.0)
96+
self.rangeSlider.changeRightKnob(value: 190.0)
97+
}
98+
99+
DispatchQueue.main.asyncAfter(deadline: .now() + 8) {
100+
//set all togheter
101+
self.rangeSlider.changeLeftKnob(value: 15.0)
102+
self.rangeSlider.changeRightKnob(value: 85.0)
84103
}
85104
}
86105

RangeUISlider.xcodeproj/project.pbxproj

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/* Begin PBXFileReference section */
2121
4548B54B252DD68F0068E389 /* build-ios.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = "build-ios.yml"; sourceTree = "<group>"; };
22+
4548B54D252DE5720068E389 /* generate_docs */ = {isa = PBXFileReference; lastKnownFileType = text; path = generate_docs; sourceTree = "<group>"; };
2223
45AA09FB225547CE005CE6EE /* RangeSelectedCalculator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RangeSelectedCalculator.swift; sourceTree = "<group>"; };
2324
45BD66D1209B60D900A19D22 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
2425
45BD66D2209B60DA00A19D22 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
@@ -61,6 +62,7 @@
6162
45BD66D2209B60DA00A19D22 /* CHANGELOG.md */,
6263
45BD66D3209B60DA00A19D22 /* LICENSE.md */,
6364
45BD66D1209B60D900A19D22 /* README.md */,
65+
4548B54D252DE5720068E389 /* generate_docs */,
6466
45E603C4233A432C00E7465D /* Package.swift */,
6567
4548B54A252DD6770068E389 /* workflows */,
6668
45E215261E8E812E00F0B8B9 /* Source */,
@@ -318,13 +320,16 @@
318320
DYLIB_INSTALL_NAME_BASE = "@rpath";
319321
INFOPLIST_FILE = Source/Info.plist;
320322
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
321-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
323+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
322324
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
325+
MARKETING_VERSION = 1.12.0;
323326
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ios.RangeUISlider;
324327
PRODUCT_NAME = "$(TARGET_NAME)";
325328
SKIP_INSTALL = YES;
329+
SUPPORTS_MACCATALYST = NO;
326330
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
327331
SWIFT_VERSION = 5.0;
332+
TARGETED_DEVICE_FAMILY = "1,2";
328333
};
329334
name = Debug;
330335
};
@@ -339,12 +344,15 @@
339344
DYLIB_INSTALL_NAME_BASE = "@rpath";
340345
INFOPLIST_FILE = Source/Info.plist;
341346
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
342-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
347+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
343348
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
349+
MARKETING_VERSION = 1.12.0;
344350
PRODUCT_BUNDLE_IDENTIFIER = it.chicio.ios.RangeUISlider;
345351
PRODUCT_NAME = "$(TARGET_NAME)";
346352
SKIP_INSTALL = YES;
353+
SUPPORTS_MACCATALYST = NO;
347354
SWIFT_VERSION = 5.0;
355+
TARGETED_DEVICE_FAMILY = "1,2";
348356
};
349357
name = Release;
350358
};

Source/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.6.0</string>
18+
<string>$(MARKETING_VERSION)</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

Source/RangeUISlider.swift

+42-19
Original file line numberDiff line numberDiff line change
@@ -523,26 +523,49 @@ import UIKit
523523
)
524524
}
525525

526-
public func changeLeftKnobPosition(position: CGFloat) {
527-
let minValue = (position - scaleMinValue) / scale
528-
leftKnob.xPositionConstraint.constant = bar.frame.width * minValue
529-
previousRangeSelectedValues = rangeSelectedCalculator.calculateRangeSelected(
530-
leftKnobPosition: leftKnob.xPositionConstraint.constant,
531-
rightKnobPosition: rightKnob.xPositionConstraint.constant,
532-
barWidth: bar.frame.width
533-
)
526+
/**
527+
Change the value of the left know programmatically.
528+
529+
- parameter value: the new value to be assigned to the left knob
530+
*/
531+
public func changeLeftKnob(value: CGFloat) {
532+
if (isValidForLeftKnob(value: value)) {
533+
let minValue = (value - scaleMinValue) / scale
534+
leftKnob.xPositionConstraint.constant = bar.frame.width * minValue
535+
previousRangeSelectedValues = rangeSelectedCalculator.calculateRangeSelected(
536+
leftKnobPosition: leftKnob.xPositionConstraint.constant,
537+
rightKnobPosition: rightKnob.xPositionConstraint.constant,
538+
barWidth: bar.frame.width
539+
)
540+
}
534541
}
535-
536-
public func changeRightKnobPosition(position: CGFloat) {
537-
let maxValue = (position - scaleMinValue) / scale
538-
rightKnob.xPositionConstraint.constant = (bar.frame.width * maxValue) - bar.frame.width
539-
previousRangeSelectedValues = rangeSelectedCalculator.calculateRangeSelected(
540-
leftKnobPosition: leftKnob.xPositionConstraint.constant,
541-
rightKnobPosition: rightKnob.xPositionConstraint.constant,
542-
barWidth: bar.frame.width
543-
)
542+
543+
/**
544+
Change the value of the right know programmatically.
545+
546+
- parameter value: the new value to be assigned to the right knob
547+
*/
548+
public func changeRightKnob(value: CGFloat) {
549+
if (isValidforRightKnob(value: value)) {
550+
let maxValue = (value - scaleMinValue) / scale
551+
rightKnob.xPositionConstraint.constant = (bar.frame.width * maxValue) - bar.frame.width
552+
previousRangeSelectedValues = rangeSelectedCalculator.calculateRangeSelected(
553+
leftKnobPosition: leftKnob.xPositionConstraint.constant,
554+
rightKnobPosition: rightKnob.xPositionConstraint.constant,
555+
barWidth: bar.frame.width
556+
)
557+
}
544558
}
545-
559+
560+
private func isValidForLeftKnob(value: CGFloat) -> Bool {
561+
return value > scaleMinValue && value < previousRangeSelectedValues.maxValue
562+
}
563+
564+
565+
private func isValidforRightKnob(value: CGFloat) -> Bool {
566+
return value <= scaleMaxValue && value > previousRangeSelectedValues.minValue
567+
}
568+
546569
private func setup() {
547570
addSubview(bar)
548571
bar.addSubview(selectedProgressView)
@@ -658,7 +681,7 @@ import UIKit
658681
}
659682

660683
@objc final func moveLeftKnob(gestureRecognizer: UIPanGestureRecognizer) {
661-
recognize(gestureRecognizer: gestureRecognizer, updateKnob: updateLeftKnobPositionUsing)
684+
recognize(gestureRecognizer: gestureRecognizer, updateKnob: updateLeftKnobPositionUsing)
662685
}
663686

664687
@objc final func moveRightKnob(gestureRecognizer: UIPanGestureRecognizer) {

0 commit comments

Comments
 (0)