UISlider: setMaximumTrackImage() method
The setMaximumTrackImage() method sets the image of the track to the right of the thumb for one or more of the slider's states, replacing the system-drawn appearance.
Syntax
setMaximumTrackImage(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:setMaximumTrackImage needs { forState }.forStatecontains an unrecognized state name:forState has no value "pressed"; expected one of: normal / highlighted / disabled / selected / focused.imageis neither aUIImagenornull:setMaximumTrackImage needs a UIImage or null.
Examples
js
const slider = new UISlider();
const dot = UIImage.systemImageNamed('circle.fill');
slider.setMaximumTrackImage(dot, { forState: ['normal'] });
console.log(slider.maximumTrackImageForState('normal') === dot);
console.log(slider.maximumTrackImageForState('highlighted') === dot);Effect
- Prints
truetwice:highlightedhasn't been set separately, so it uses thenormalimage. - The right track is displayed as this image. Not verified in the simulator.
Corresponding iOS API
-[UISlider setMaximumTrackImage:forState:]. The state is a bitmask in ObjC; here it is written as an array.
See also
maximumTrackImageForState(): reading the image for a statecurrentMaximumTrackImage: the image used for the current statesetThumbImage(),setMinimumTrackImage()