user2428168 user2428168 - 1 year ago 103
iOS Question

Changing UISlider Images with Swift

I'm trying to change the default images for UISliders with Swift. I'm editing


In Objective C you would do this:

UIImage *maxImage = [UIImage imageNamed:@"slider-track.png"];
[[UISlider appearance] setMaximumTrackImage:maxImage forState:UIControlStateNormal];

I've tried converting to Swift but have not been successful:

var maxImage:UIImage = UIImage (named:"slider-track.png")
UISlider.setMaximumTrackImage(image: maxImage, forState: UIControlStateNormal)

The first line is fine, but the second gives an error.

What is the correct syntax for the second line?


Answer Source

From Doc Example

let leftTrackImage = UIImage(named: "slider_blue_track")
        customSlider.setMinimumTrackImage(leftTrackImage, forState: .Normal)