Reputation: 2569
I'm trying to add Touch Bar support for Mac Catalyst app.
And the NSSliderTouchBarItem is marked as available for catalyst, but the doubleValue of the slider is not available. Is there another way to get value from it?
Upvotes: 1
Views: 169
Reputation: 228
More great uses Mhd Hejazi's Dynamic Library
touchBarVolumeSlider = NSSliderTouchBarItem(identifier: identifier)
touchBarVolumeSlider.label = "V"
touchBarVolumeSlider.action = #selector(changeSliderValue)
touchBarVolumeSlider.setValue(0.5, forKey: "doubleValue")
Dynamic(touchBarVolumeSlider).slider.setContinuous(false)
Now the action only calls changeSliderValue when the slider stops moving. I look at here to get details on the underlying methods and properties.
Upvotes: 1
Reputation: 228
To get the position of the slider, use this:
@objc func changeSpeed(sender: NSSliderTouchBarItem) {
let value = sender.value(forKey: "doubleValue") as! Double
print(value)
}
To set its position:
slider.setValue(0.5, forKey: "doubleValue")
The value is between 0 and 1
Upvotes: 0