UISlider: setThumbImage() method
The setThumbImage() method sets the thumb image for one or more of the slider's states, replacing the system-drawn appearance.
Syntax
setThumbImage(image, { forState })Parameters
image
UIImage, or null. null removes the image for these states.
options.forState
An array of state names, required. Usually ['normal']: states that haven't been set separately use the normal image. The state names are 'normal', 'highlighted' (finger pressing), 'disabled', 'selected', and 'focused'; see States.
Return value
None (undefined).
Exceptions
TypeError
forStatenot passed:setThumbImage needs { forState }.forStatecontains an unrecognized state name:forState has no value "pressed"; expected one of: normal / highlighted / disabled / selected / focused.imageis neither aUIImagenornull:setThumbImage needs a UIImage or null.
Examples
js
const slider = new UISlider();
const dot = UIImage.systemImageNamed('circle.fill');
slider.setThumbImage(dot, { forState: ['normal'] });
console.log(slider.thumbImageForState('normal') === dot);
console.log(slider.thumbImageForState('highlighted') === dot);Effect
- Prints
truetwice:highlightedhasn't been set separately, so it uses thenormalimage. - The thumb is displayed as this image. Not verified in the simulator.
Corresponding iOS API
-[UISlider setThumbImage:forState:]. The state is a bitmask in ObjC; here it is written as an array.
See also
thumbImageForState(): reading the image for a statecurrentThumbImage: the image used for the current statesetMinimumTrackImage(),setMaximumTrackImage()