Posted By

negzero7 on 09/20/13


Tagged

MonoTouch ios c#


Versions (?)

Set Intervals for sliders


 / Published in: C#
 

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.

  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  

You need to login to post a comment.