Skip to content

Instantly share code, notes, and snippets.

@Gujci
Created October 8, 2019 13:39
Show Gist options
  • Save Gujci/7a7c37ce6a4bc29c498ca3c593bf2b69 to your computer and use it in GitHub Desktop.
Save Gujci/7a7c37ce6a4bc29c498ca3c593bf2b69 to your computer and use it in GitHub Desktop.
impost SwiftUI
struct TactileSliderView: UIViewRepresentable {
@Binding var value: Float
func makeUIView(context: Context) -> TactileSlider {
let slider = TactileSlider()
slider.setValue(value, animated: false)
slider.addTarget(context.coordinator, action: #selector(context.coordinator.valueChanged), for: .valueChanged)
return slider
}
func updateUIView(_ uiView: TactileSlider, context: UIViewRepresentableContext<TactileSliderView>) { }
func makeCoordinator() -> TactileSliderView.Coordinator { Coordinator(self) }
class Coordinator: NSObject {
var parent: TactileSliderView
init(_ slider: TactileSliderView) {
parent = slider
}
@objc func valueChanged(_ sender: TactileSlider) {
parent.value = sender.value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment