An iOS range selection slider compatible with UIKit and SwiftUI. Developed using autolayout and highly customizable using @IBDesignabled and @IBInspectable or programmatically. It support also RTL (right to left) languages automatically out of the box.
Installation
There are three ways to install RangeUISlider in your project: manual installation, as a stand-alone framework or using cocoapods.
Manual installation
To manually install RangeUISlider simply drag and drop all the file contained in the Source folder inside your project.
Framework
RangeUISlider is available also as a framework. To install it follow the standard procedure used to install a custom cocoa touch framework:
drag the RangeUISlider.xcodeproj inside your project
add it to the Embedded Binaries/Linked Frameworks and Libraries section of your project.
See the RangeUISliderDemo demo project/target for an example of the setup of the framework.
CocoaPods
RangeUISlider is also available as a pod on CocoaPods.
Add the dependency to your Podfile similar to the following:
target 'MyApp' do
pod 'RangeUISlider', '~> 3.0'
end
and then run pod install (or pod update).
Swift Package Manager (SPM)
RangeUISlider is also available as a SPM package. Add it from the project configuration using the Github repository url. Choose master or a tag. If you choose the tag it must be >= 1.11.0.
Usage
You can use RangeUISlider in three ways:
in a UIKit project using Interface Builder (thanks to @IBDesignable and @IBInspectable )
in a UIKit project programmatically
in a SwiftUI project using the RangeSlider wrapper created using UIViewRepresentable
Interface builder
To levearege the power of the RangeUISlider in interface builder:
drag a UIView into you storyboard
set RangeUISlider as custom class of that view
IMPORTANT: set also the Module to RangeUISlider if you used cocoapods or the framework version during installation
start editing it using interface builder (and levearage the power of @IBDesignabled and @IBInspectable)
Here you can find a video tutorial for the setup with Interface Builder.
Programmatic
You can also use RangeUISlider as a programmatic UI component by setting all the property you need in your code. Take a look at the RangeUISliderDemo project to see multiple example (e.g. take a look at this contrroller. In particular, remember to set translatesAutoresizingMaskIntoConstraints = false for the slider to use autolayout. Below you can find a simple example.
You can use RangeUISlider in a SwiftUI application/screen by leveraging the RangeSlider wrapper created using UIViewRepresentable. Below you can find a small example of the usage in a simple screen. You can find more example in the RangeUISliderDemo demo project (look here).
You can access the range values in two ways, depending on the fact that you’re using RangeUISlider in a UIKit or SwiftUI view:
for UIKit, use RangeUISliderDelegate and the delegate property
for SwiftUI, use the RangeSlider.minValueSelected and RangeSlider.maxValueSelected binding values
UIKit - RangeUISliderDelegate
To get the current values from the slider in a UIKit project, set the slider delegate property. The delegate of RangeUISlider must implement the RangeUISliderDelegate protocol, that has three methods. See code below.
@objc public protocol RangeUISliderDelegate {
/**
Calls the delegate when the user has started the change of the range.
*/
@objc optional func rangeChangeStarted()
/**
Calls the delegate when the user is changing the range by moving the knobs.
- parameter event: the change event data. See `RangeUISliderChangeEvent`.
*/
@objc optional func rangeIsChanging(event: RangeUISliderChangeEvent)
/**
Calls the delegate when the user has finished the change of the range.
- parameter event: the change finish event data. See `RangeUISliderChangeFinishedEvent`.
*/
@objc func rangeChangeFinished(event: RangeUISliderChangeFinishedEvent)
}
SwiftUI - Binding values
You can access the values of the slider in a SwiftUI project by passing two bindings properties to the RangeSlider init. See the example below.
This is the list of the RangeUISlider customizable properties directly from Interface Builder/programmatically (UIKit) or by using the RangeSlider access modifiers (SwiftUI):
identifier of the slider (Int )
range minimum value (CGFloat)
range maximum value (CGFloat)
step increment value (CGFloat)
default starting value left knob (CGFloat)
default starting value right knob (CGFloat)
range selected color
range selected image (override range selected color property)
range selected edge inset top, left, bottom, right (used only if range selected image has been setted)
range selected gradient color 1 (override range selected color and image)
range selected gradient color 1 (override range selected color and image)
range selected gradient start point (used only if range selected gradients color has been choosed)
range selected gradient end point (used only if range selected gradients color has been choosed)
range not selected color
range not selected image (override range not selected color property)
range not selected edge inset top, left, bottom, right (used only if range not selected image has been setted)
range not selected gradient color 1 (override range not selected color and image)
range not selected gradient color 1 (override range not selected color and image)
range not selected gradient start point (used only if range not selected gradients color has been choosed)
range not selected gradient end point (used only if range not selected gradients color has been choosed)
left knob width
left knob height
left knob corners radius
left knob color
left knob image (override color)
left knob shadow opacity
left knob shadow color
left knob shadow offset
left knob shadow radius
left knob gradient color 1 (override left knob color and image)
left knob gradient color 2 (override left knob color and image)
left knob gradient start point (used only if left knob gradients color has been choosed)
left knob gradient end point (used only if left knob gradients color has been choosed)
left knob border width
left knob border color
right knob width
right knob height
right knob corners radius
right knob color
right knob image (override color)
right knob shadow opacity
right knob shadow color
right knob shadow offset
right knob shadow radius
right knob gradient color 1 (override right knob color and image)
right knob gradient color 2 (override right knob color and image)
right knob gradient start point (used only if right knob gradients color has been choosed)
right knob gradient end point (used only if right knob gradients color has been choosed)
In the following screenshot you can find some examples of the level of customization that it is possible to reach. You can find this examples in the demo project.
RangeUISlider
An iOS range selection slider compatible with
UIKit
andSwiftUI
. Developed using autolayout and highly customizable using@IBDesignabled
and@IBInspectable
or programmatically. It support also RTL (right to left) languages automatically out of the box.Installation
There are three ways to install
RangeUISlider
in your project: manual installation, as a stand-alone framework or using cocoapods.Manual installation
To manually install
RangeUISlider
simply drag and drop all the file contained in the Source folder inside your project.Framework
RangeUISlider
is available also as a framework. To install it follow the standard procedure used to install a custom cocoa touch framework:See the
RangeUISliderDemo
demo project/target for an example of the setup of the framework.CocoaPods
RangeUISlider is also available as a pod on CocoaPods. Add the dependency to your Podfile similar to the following:
and then run pod install (or pod update).
Swift Package Manager (SPM)
RangeUISlider
is also available as a SPM package. Add it from the project configuration using the Github repository url. Choose master or a tag. If you choose the tag it must be >= 1.11.0.Usage
You can use RangeUISlider in three ways:
UIKit
project using Interface Builder (thanks to@IBDesignable
and@IBInspectable
)UIKit
project programmaticallySwiftUI
project using theRangeSlider
wrapper created usingUIViewRepresentable
Interface builder
To levearege the power of the
RangeUISlider
in interface builder:RangeUISlider
as custom class of that view@IBDesignabled
and@IBInspectable
)Here you can find a video tutorial for the setup with Interface Builder.
Programmatic
You can also use
RangeUISlider
as a programmatic UI component by setting all the property you need in your code. Take a look at theRangeUISliderDemo
project to see multiple example (e.g. take a look at this contrroller. In particular, remember to settranslatesAutoresizingMaskIntoConstraints = false
for the slider to use autolayout. Below you can find a simple example.SwiftUI
You can use
RangeUISlider
in aSwiftUI
application/screen by leveraging theRangeSlider
wrapper created usingUIViewRepresentable
. Below you can find a small example of the usage in a simple screen. You can find more example in theRangeUISliderDemo
demo project (look here).Access range values
You can access the range values in two ways, depending on the fact that you’re using
RangeUISlider
in aUIKit
orSwiftUI
view:UIKit
, useRangeUISliderDelegate
and the delegate propertySwiftUI
, use theRangeSlider.minValueSelected
andRangeSlider.maxValueSelected
binding valuesUIKit - RangeUISliderDelegate
To get the current values from the slider in a
UIKit
project, set the slider delegate property. The delegate ofRangeUISlider
must implement theRangeUISliderDelegate
protocol, that has three methods. See code below.SwiftUI - Binding values
You can access the values of the slider in a
SwiftUI
project by passing two bindings properties to theRangeSlider
init. See the example below.Change knob current values programmatically (only
UIKit
)You can also change the values of the slider knobs by calling this two API:
func changeLeftKnob(value: CGFloat)
to change programmatically the left knob valuefunc changeRightKnob(value: CGFloat)
to change programmatically the right knob valueThe
value
passed to these methods should be in the slider range values (see the next section of the documentation to understand how to customize the slider range). Take a look at the example in the ChangeProgrammaticViewController contained in the demo project to understand how to use these API.Customizable properties
This is the list of the
RangeUISlider
customizable properties directly from Interface Builder/programmatically (UIKit
) or by using theRangeSlider
access modifiers (SwiftUI
):Documentation
You can find the complete api documentation on fabrizioduroni.it.
Examples
In the following screenshot you can find some examples of the level of customization that it is possible to reach. You can find this examples in the demo project.