Search code examples
ioslogicconditional-statementsuislider

UISlider.value logic / conditional


Using this:

if (_sizeSlider.value <= 0.25) {
    //set to 256sq
    _exportSize = 256;
} else if ((_sizeSlider.value >= 0.26) && (_sizeSlider.value < 0.5)) {
    //set to 512
    _exportSize = 512;
} else if ((_sizeSlider.value >= 0.5) && (_sizeSlider.value < 0.75)) {
    //set to 1024
    _exportSize = 1024;
} else {
    //set to 1800
    _exportSize = 1800;
}

If the slider is exactly at 0.25, it thinks it's at 1. The problem does not happen at any other points. Any ideas why?

Thanks.


Solution

  • There is a gap between 0.25 and 0.26 which is not covered in your logic. This will fall through to the final case.