Created
October 8, 2019 13:39
-
-
Save Gujci/7a7c37ce6a4bc29c498ca3c593bf2b69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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