Reputation: 24501
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];
Upvotes: 33
Views: 18873
Reputation: 1343
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()
Upvotes: 12
Reputation: 3378
Objc
[sli setThumbImage:[[[UIImage alloc] init] autorelease] forState:UIControlStateNormal];
Swift version
sli.setThumbImage(UIImage(), for: .normal)
Upvotes: 63
Reputation: 149
One line solution:
[_slider setThumbImage:[UIImage new] forState:UIControlStateNormal];
Upvotes: 1
Reputation: 4105
The easiest way is simply setting the Thumb Tint colour to Clear on the Interface Builder - like so...
Voila!
Upvotes: 17
Reputation: 16861
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.
Upvotes: 0