Change slider direction

可紊 提交于 2019-12-13 03:24:42

问题


I would to change a slider's direction from right to left. I want 0 to be on the right side.

For example:

My slider:

let slider = UISlider()
slider.minimumValue = 0
slider.maximumValue = 0
slider.isContinuous = true
slider.tintColor = UIColor.red
slider.value = 0
slider.translatesAutoresizingMaskIntoConstraints = false

I'm not sure if this is possible.


回答1:


Just flip the slider horizontally:

slider.transform = CGAffineTransform(scaleX: -1, y: 1)



回答2:


Or take the slider value with

let realValue = slider.maximumValue - slider.minimumValue + slider.value;

And set it using

slider.value = slider.maximumValue - slider.minimumValue + realValue;

Like that the slider does not need to be visually transformed, and will still respond correctly to any other input methods (keyboard, accessibility input, etc)



来源:https://stackoverflow.com/questions/48522524/change-slider-direction

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!