Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在swift中设置UIslider拇指图像_Ios_Swift_Uislider - Fatal编程技术网

Ios 在swift中设置UIslider拇指图像

Ios 在swift中设置UIslider拇指图像,ios,swift,uislider,Ios,Swift,Uislider,我想在这里设置喜欢音乐应用程序的拇指是ss 我想要 我有 这是代码 durationSlider.setThumbImage(UIImage(named: "Slider_indicator.png"), forState: UIControlState.Normal) durationSlider.setThumbImage(UIImage(named: "Slider_indicator.png"), forState: UIControlState.Highli

我想在这里设置喜欢音乐应用程序的拇指是ss

我想要

我有

这是代码

        durationSlider.setThumbImage(UIImage(named: "Slider_indicator.png"), forState: UIControlState.Normal)
    durationSlider.setThumbImage(UIImage(named: "Slider_indicator.png"), forState: UIControlState.Highlighted)

在这里,您现在只想显示拇指的下方部分。所以你需要把上面一半的图像弄清楚。请检查我随附的答案图片

[slider setThumbImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];


尝试此操作并下载缩放图像(如果需要)

如果要剪裁拇指图像的顶部,应使用:

public func thumbRectForBounds(bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect
因此,将此添加到您的代码中:

durationSlider.thumbRectForBounds(...)
并将
thumbRect
CGRect
设置为将
durationSlider.frame.origin.y
的值作为其自身的
origin.y

下面是另一个临时解决方案,我将很快回到
thumbRectForBounds
方法:

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

是返回图像并显示我的问题是拇指图像上半部分不像第一个图像那样显示我想要这样你不想在滑块上显示拇指图像的上半部分,对吗?查看我的答案,将该图像设置为拇指图像。我已经在我的一个项目中实现了这一点。你能告诉我如何创建视频应用程序@John吗