user2428168 user2428168 - 4 months ago 26
iOS Question

Changing UISlider Images with Swift

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

didFinishLaunchingWithOptions
in
AppDelegate
.

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?

Thanks

Answer

From Doc Example

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