开发者

Hide UISlider thumb image

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:UIControlS开发者_开发问答tateNormal];


Much simpler:

Objc

[sli setThumbImage:[[[UIImage alloc] init] autorelease] forState:UIControlStateNormal];

Swift version

sli.setThumbImage(UIImage(), for: .normal)


The easiest way is simply setting the Thumb Tint colour to Clear on the Interface Builder - like so...

Hide UISlider thumb image

Voila!


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.

    let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
    UIGraphicsBeginImageContextWithOptions(CGSize(width: 1, height: 1), false, 0)
    UIColor.clear.setFill()
    UIRectFill(rect)
    if let blankImg = UIGraphicsGetImageFromCurrentImageContext() {
        slider.setThumbImage(blankImg, for: .normal)
    }
    UIGraphicsEndImageContext()


One line solution:

[_slider setThumbImage:[UIImage new] forState:UIControlStateNormal];


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜