Attach a SeekPreview to a seekBar to show small preview images of the seek action.
You just need to create a SeekPreview
object, pass it a SeekPreviewDelegate
to provide preloaded preview images, and attach the preview to a UISlider
that belongs to the same view hierarchy as the preview.
let slider = UISlider()
view.addSubview(slider)
// then add constraints to position the slider on the screen
let preview = SeekPreview()
preview.delegate = self
view.addSubview(preview)
// then add constraints to position the preview on the screen
// (put the preview on top of the slider with some vertical spacing)
preview.attachToSlider(slider: slider) // This needs to be called after views are added in the same view hierarchy
You need to set the preview delegate to provide the preview images when requested.
Images will be requested synchronously on the main thread as soon as the value changes from the slider. Therefore we suggest to prefetch those images in advance.
Since you probably don't have a preview for each specific value that the slider can have, you are expected to always return the closest preview that you have for that value.
N.B. We don't provide a way to prefetch those images. This is NOT in the scope of this library.
You can create a SeekPreview with a custom animator. You just need to create a class that conforms to the SeekPreviewAnimator
protocol and pass it in the init.
You can just change the SeekPreview properties: borderColor
, borderWidth
and cornerRadius
to change the UI of the inner preview holding the images.
You can also create a view directly from the storyboard.
You can customize the Appearence with the attribute inspector.
You can also attach Slider and Delegate via the outlets (much like you would do with a TableView delegate and dataSource).
In case you should use the storyboard you'll have the default animator, but you can later change it programmatically.
To run the example project, clone the repo, and run pod install
from the Example directory first.
SeekPreview is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SeekPreview'
Enricoza, [email protected]
SeekPreview is available under the MIT license. See the LICENSE file for more info.