Change slider direction

2019-08-24 13:26发布

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

For example:

Reversed slider

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.

2条回答
太酷不给撩
2楼-- · 2019-08-24 14:05

Just flip the slider horizontally:

slider.transform = CGAffineTransform(scaleX: -1, y: 1)
查看更多
相关推荐>>
3楼-- · 2019-08-24 14:10

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)

查看更多
登录 后发表回答