Search code examples
iosobjective-cuislider

UISlider with left-side increment different than right-side increment


I'm using a UISlider to adjust the white balance of an image, and it's calculated in ºK (albeit, from what I understand of light, I think it's backwards? Nevertheless...)

If I set the default to 5000ºK, when I move the slider left, the image is drastically more blue than it is when I move it to the right. To mitigate this, I painstakingly created a left-hand increment that's different from the right-hand increment (the left extends exactly 1/4 that of the right, so that the min value is 4000ºK and the max is 9000ºK).

Now this works, but the slider is no longer in the middle:

enter image description here

Is there a way I can adjust the slider's range so that the left-hand side is magnified 4x that of the right?


Solution

  • You can use this formula:

    alpha: value of slider (0-1)
    
    a: K value (e.g. 5000)
    
    min: 4000
    
    max: 9000
    
    /// for getting alpha from K value
    alpha = ((a - min)*4)/((a - min)*4 + (max - a));
    
    /// for getting K value from alpha
    a = (alpha*max - 4*min*(alpha - 1))/(4 - 3*alpha);
    

    I did this myself. So need test more.