UISlider maximum values adjustments
I am having three sliders and these shows the percentages for different elements what i need the max value of all is 100 (a+b+c=100).
Now these all are dependent to each other and helps in making a pie chart.
currently all can set to 开发者_开发百科max value that is 100.
how can make this dependency and max value logically.
Thanx in advance.
In methods where you handle your sliders changes adjust maximum values for all sliders depending on current ones, e.g.:
- (void) sliderChanged:(UISlider*)sender{
slider1.maximumValue = 100 - slider2.value - slider3.value;
// etc
}
Edit: Adjusting maximum value may indeed lead to not behaviour. Instead to ensure that the sum does not exceed 100 you can manually adjust slider's value if it is more than desired:
- (void) sliderChanged:(UISlider*)sender{
//sender is slider1
sender.value = MIN(sender.value, 100 - slider2.value - slider3.value);
// etc
}
精彩评论