UISlider maximum values adjustments

怎甘沉沦 提交于 2019-12-22 12:18:12

问题


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.


回答1:


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
}


来源:https://stackoverflow.com/questions/5978404/uislider-maximum-values-adjustments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!