How to read size of UISlider thumb image

前端 未结 5 1262
一生所求
一生所求 2021-01-18 07:02

I\'m trying to position an additional UIView centered above the thumb in a UISlider. To do this, I need the width of the thumb image. In iOS6, this works fine. I can use:

5条回答
  •  耶瑟儿~
    2021-01-18 07:49

    Here is another one that works, however it is a little "hackier" than the first one, and makes an assumption on the default thumb Image width won't change in future versions of iOS (past 11)

    - (CGFloat)thumbImageWidth // default thumb image is 30 px,
    {
        double imgThumbImageWidth = self.currentThumbImage.size.width;
        if (imgThumbImageWidth && imgThumbImageWidth != 0 && imgThumbImageWidth != thumbImageWidth) {
            thumbImageWidth = imgThumbImageWidth;
        }
        else if (!thumbImageWidth || thumbImageWidth == 0) { // No custom image set, use 30
            thumbImageWidth = 31;
        }
        return thumbImageWidth;
    }
    

提交回复
热议问题