How To Change UI Slider Thumb Image In Swift Programmatically

Sometimes you want to change the slider thumb image to something custom.

How To Change UI Button Image Swift Programmatically

customSlider.setThumbImage(thumbImage, forState: .normal)

If you need to load the image from your assets, it’s best to do it safely in a if let statement

if let thumbImage = UIImage(named: "thumb-image") {
    customSlider.setThumbImage(thumbImage, forState: .normal)

Of course you can just define the image in the same line if you want:

customSlider.setThumbImage( UIImage(named: "thumb-image"), for: .normal)
If you liked this post and want to learn more, check out The Complete iOS Developer Bootcamp. Speed up your learning curve - hundreds of students have already joined. Thanks for reading!

Eddy Chung

I teach iOS development on

Similar Posts