Set Intervals for sliders


/ Published in: C#
Save to your folder(s)

Call this method to set the intervals for a UISlider in Monotouch. You can remove the textbox parameter if you don't have them linked to sliders.


Copy this code and paste it in your HTML
  1. // Set interval for sliders, Update txtboxes, Update gross weight
  2. void setInterval(UISlider slider, UITextField txtBox, int interval){
  3.  
  4. // get the nearest interval value
  5. for(int i=(int)slider.MinValue; i<=(int)slider.MaxValue; i=i+interval){
  6.  
  7. if(slider.Value > i && slider.Value < i + interval){
  8. if(slider.Value - i < i + interval - slider.Value){
  9. slider.Value = i;
  10. }else{
  11. slider.Value = i + interval;
  12. }
  13. break;
  14. }
  15. }
  16. txtBox.Text = slider.Value.ToString();
  17. UpdateGrossWeight ();
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.