我试图在 UISlider 中的拇指上方放置一个额外的 UIView。为此,我需要拇指图像的宽度。在 iOS6 中,这工作正常。我可以使用:
CGFloat thumbWidth = self.navSlider.currentThumbImage.size.width;
(如本答案所示:How to get the center of the thumb image of UISlider)
这在 iOS7 中返回 0.0f。我也尝试使用以下方式阅读它:
UIImage *thumb = [self.navSlider thumbImageForState:UIControlStateNormal];
但拇指最终为零。
是否可以读取默认 slider 缩略图的大小?还是我必须找到它,设置一个常量,Apple 以后怎么不更改它?
最佳答案
currentThumbImage
属性的文档说:
If no custom thumb images have been set using the setThumbImage:forState: method, this property contains the value nil. In that situation, the receiver uses the default thumb image for drawing.
thumbImageForState:
上的文档不太清楚:
Return Value The thumb image associated with the specified state, or nil if an appropriate image could not be retrieved.
我认为您在尝试计算默认拇指大小时可能运气不佳。安装一个看起来与系统图像完全一样的“自定义”缩略图怎么样?这将解决 Apple 从您下面更换它的问题。
关于ios - 如何读取 UISlider 缩略图的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21313796/