Thumb image does not move to the edge of UISlider

后端 未结 9 1149
有刺的猬
有刺的猬 2021-02-13 02:14

Thumb image does not move to the edge even when it\'s value is max or min.

Does anyone know how to make it move all the way to the edge of the slider?

9条回答
  •  渐次进展
    2021-02-13 03:01

    It may not be the most efficient, but it seems to work fine. This is another simple way to do it in Objective-C. Basically, you'll play around with the "pixelAdjustment" variable to get the slider where you want it.

    - (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:   (float)value {
        float multValue = value - 0.5;
        float pixelAdjustment = 30; //This is the value you need to change depending on the size of the thumb image of your slider.
        float xOriginDelta = (multValue * (bounds.size.width - pixelAdjustment));
    
        CGRect adjustedRect = CGRectMake(bounds.origin.x + xOriginDelta, bounds.origin.y, bounds.size.width, bounds.size.height);
        return adjustedRect;
    }
    

提交回复
热议问题