Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.

id title brief sdk
Specify Slider Value
This recipe shows how to specify the range of a slider and access its value.


To create a slider and set its initial value:

  1. Create a UISlider and add it to the View:
slider = new UISlider(new CGRect(100,  30, 210, 20));
View.Add (slider);
  1. Set the slider minimum, maximum and initial value:
slider.MinValue = 0f;
slider.MaxValue = 1f;
slider.Value = 0.5f; // initial value
  1. Attach an event to respond to any changes in the slider:
slider.ValueChanged += HandleValueChanged; // defined below
  1. Create a method to handle the changed value. In the example the value is displayed in a label as the slider is dragged:
void HandleValueChanged (object sender, EventArgs e)
{   // display the value in a label
   label.Text = slider.Value.ToString ();

The sample looks like this when running: