隐藏 UISlider 拇指图像
我正在尝试创建一个没有拇指图像的 UISlider。
我该怎么做,这是我到目前为止的代码:
UISlider *sli = [[UISlider alloc] initWithFrame:progressView.frame];
[sli setThumbImage:nil forState:UIControlStateNormal];
[sli setBackgroundColor:[UIColor clearColor]];
[sli setMinimumTrackImage:[[UIImage imageNamed:@"ProgressBlueCap.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[sli setMaximumTrackImage:[[UIImage imageNamed:@"ProgressBlueCapRight.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
I am trying to create a UISlider without the thumb image.
How can I do this, this is my code so far:
UISlider *sli = [[UISlider alloc] initWithFrame:progressView.frame];
[sli setThumbImage:nil forState:UIControlStateNormal];
[sli setBackgroundColor:[UIColor clearColor]];
[sli setMinimumTrackImage:[[UIImage imageNamed:@"ProgressBlueCap.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[sli setMaximumTrackImage:[[UIImage imageNamed:@"ProgressBlueCapRight.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
更简单:
Objc
Swift 版本
Much simpler:
Objc
Swift version
最简单的方法就是在 Interface Builder 上将 Thumb Tint 颜色设置为 Clear - 就像这样...
瞧!
The easiest way is simply setting the Thumb Tint colour to Clear on the Interface Builder - like so...
Voila!
这是一个旧线程,但我发现了它,所以其他人也可以。
这是 Swift 中的解决方案。我在这里以编程方式创建一个空白的 UIImage,然后将其分配给拇指。
This is an old thread but I found it so someone else may as well.
Here's a solution to this in Swift. I'm creating a blank UIImage here programatically and then assigning it to the thumb.
一条线解决方案:
One line solution:
我会尝试子类化
UISlider
并覆盖-thumbRectForBounds:trackRect:value:
以返回 NSZeroRect。如果这不起作用,请尝试覆盖-thumbImageForState:
以返回 nil。I'd try subclassing
UISlider
and override-thumbRectForBounds:trackRect:value:
to return NSZeroRect. If that doesn't do it, try overriding-thumbImageForState:
to return nil.