![slider.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/205312/slider.png)
How to enable "Snap to Tick" for a slider in App Designer?
30 次查看(过去 30 天)
显示 更早的评论
Hi, I want to know how to make a slider move discretely rather than continuously. As an example, I want the slider to jump from 1 to 2 when I move it. In other words, I need to enable the "Snap to Tick" feature.
Thanks in advance.
3 个评论
Jesse Beaupre
2023-6-15
In the callback make the slider value rounded and then set the slider position to this rounded value.
回答(1 个)
Kevin Chng
2019-2-22
![Untitled.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/205320/Untitled.png)
Is it what you expect? If you are using app designer, on your left hand side bottom, there is configuration you may edit. Empty the minor tick, and modify the major tick to 1,2,3,4,5.
Don't forgot to change the limit as well to 0,5
3 个评论
Kevin Chng
2019-2-25
编辑:Kevin Chng
2019-2-25
The only way i can think about it is to create a callback function, then use the round off method to readjust the value of slider if user move the handle to the place between intervals.
Create a callback function for your slider
value = app.Slider.Value;
app.Slider.Value=round( value / 20 ) * 20;
You may change the value of 20 to 2, if the interval is 2.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!