Search code examples
iphoneobjective-cuislider

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:UIControlStateNormal];

Solution

  • Much simpler:

    Objc

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

    Swift version

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