ios - 如何读取 UISlider 缩略图的大小

标签 ios iphone uislider

我试图在 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/

相关文章:

ios - 实时更改 AVSpeechUtterance 速率

ios - Pod init 或 pod update 出现以下错误

ios - 重新加载相同的 ViewController,就像使用 segue 调用一样

ios - 无法启动应用程序(验证开发者应用程序证书)

ios - 如何忽略 iOS6 UITextField 中的占位符文本

javascript - 如何使用 jQuery 选择下一个 div?

ios - 在 Swift 中返回 self

iphone - 我是否总是必须在 -viewDidLoad 方法中调用 [super viewDidLoad] ?

javascript - 如何使用两个 Ui Range Sliders 对相同数据进行排序

iOS UISlider VoiceOver 禁用说出值