快速设置 UIslider 拇指图像 [英] set UIslider thumb image in swift
本文介绍了快速设置 UIslider 拇指图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在这里设置像 musi app 这样的拇指是 ss
I want to set thumb of like musi app here is ss
我想要
我有
这是代码
durationSlider.setThumbImage(UIImage(named: "Slider_indicator.png"), forState: UIControlState.Normal)
durationSlider.setThumbImage(UIImage(named: "Slider_indicator.png"), forState: UIControlState.Highlighted)
推荐答案
如果你想剪掉拇指图像的顶部,你应该使用:
If you want to clip the top part of the thumbImage, you should use:
public func thumbRectForBounds(bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect
因此将其添加到您的代码中:
So add this to your code:
durationSlider.thumbRectForBounds(...)
并将thumbRect
的CGRect
设置为durationSlider.frame.origin.y
的值作为它自己的origin.y
.
And set the CGRect
of the thumbRect
to have the value of durationSlider.frame.origin.y
as its own origin.y
.
这是另一个临时解决方案,我很快就会回到 thumbRectForBounds
方法:
Here's another temporary solution, I'll get back to the thumbRectForBounds
method shortly:
let mask = CAGradientLayer(layer: durationSlider.layer)
let lineTop = (durationSlider.bounds.height/2 - 0.5) / durationSlider.bounds.height
mask.frame = durationSlider.bounds
mask.colors = [UIColor.clearColor().CGColor, UIColor.blackColor().CGColor]
mask.locations = [lineTop, lineTop]
durationSlider.layer.mask = mask
这篇关于快速设置 UIslider 拇指图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文