iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UISlider Class Reference

Options
Deployment Target:

On This Page
Language:

UISlider

A UISlider object is a visual control used to select a single value from a continuous range of values. Sliders are always displayed as horizontal bars. An indicator, or thumb, notes the current value of the slider and can be moved by the user to change the setting. More...

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.
  • value value Property

    Contains the receiver’s current value.

    Declaration

    Swift

    var value: Float

    Objective-C

    @property(nonatomic) float value

    Discussion

    Setting this property causes the receiver to redraw itself using the new value. To render an animated transition from the current value to the new value, you should use the setValue:animated: method instead.

    If you try to set a value that is below the minimum or above the maximum value, the minimum or maximum value is set instead. The default value of this property is 0.0.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sets the receiver’s current value, allowing you to animate the change visually.

    Declaration

    Swift

    func setValue(_ value: Float, animated animated: Bool)

    Objective-C

    - (void)setValue:(float)value animated:(BOOL)animated

    Parameters

    value

    The new value to assign to the value property

    animated

    Specify YEStrue to animate the change in value when the receiver is redrawn; otherwise, specify NOfalse to draw the receiver with the new value only. Animations are performed asynchronously and do not block the calling thread.

    Discussion

    If you try to set a value that is below the minimum or above the maximum value, the minimum or maximum value is set instead. The default value of this property is 0.0.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    value

  • Contains the minimum value of the receiver.

    Declaration

    Swift

    var minimumValue: Float

    Objective-C

    @property(nonatomic) float minimumValue

    Discussion

    If you change the value of this property, and the current value of the receiver is below the new minimum, the current value is adjusted to match the new minimum value automatically.

    The default value of this property is 0.0.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Contains the maximum value of the receiver.

    Declaration

    Swift

    var maximumValue: Float

    Objective-C

    @property(nonatomic) float maximumValue

    Discussion

    If you change the value of this property, and the current value of the receiver is above the new maximum, the current value is adjusted to match the new maximum value automatically.

    The default value of this property is 1.0.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Contains a Boolean value indicating whether changes in the sliders value generate continuous update events.

    Declaration

    Swift

    var continuous: Bool

    Objective-C

    @property(nonatomic, getter=isContinuous) BOOL continuous

    Discussion

    If YEStrue, the slider sends update events continuously to the associated target’s action method. If NOfalse, the slider only sends an action event when the user releases the slider’s thumb control to set the final value.

    The default value of this property is YEStrue.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Contains the image that is drawn on the side of the slider representing the minimum value.

    Declaration

    Swift

    var minimumValueImage: UIImage?

    Objective-C

    @property(nonatomic, retain) UIImage *minimumValueImage

    Discussion

    The image you specify should fit within the bounding rectangle returned by the minimumValueImageRectForBounds: method. If it does not, the image is scaled to fit. In addition, the receiver’s track is lengthened or shortened as needed to accommodate the image in its bounding rectangle.

    This default value of this property is nil.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Contains the image that is drawn on the side of the slider representing the maximum value.

    Declaration

    Swift

    var maximumValueImage: UIImage?

    Objective-C

    @property(nonatomic, retain) UIImage *maximumValueImage

    Discussion

    The image you specify should fit within the bounding rectangle returned by the maximumValueImageRectForBounds: method. If it does not, the image is scaled to fit. In addition, the receiver’s track is lengthened or shortened as needed to accommodate the image in its bounding rectangle.

    This default value of this property is nil.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The color used to tint the standard minimum track images.

    Declaration

    Swift

    var minimumTrackTintColor: UIColor?

    Objective-C

    @property(nonatomic, retain) UIColor *minimumTrackTintColor

    Discussion

    Setting this property removes any custom minimum track images associated with the slider.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Contains the minimum track image currently being used to render the receiver. (read-only)

    Declaration

    Swift

    var currentMinimumTrackImage: UIImage! { get }

    Objective-C

    @property(nonatomic, readonly) UIImage *currentMinimumTrackImage

    Discussion

    Sliders can have different track images for different control states. The image associated with this property reflects the minimum track image associated with the currently active control state. To get the minimum track image for a different control state, use the minimumTrackImageForState: method.

    If no custom track images have been set using the setMinimumTrackImage:forState: method, this property contains the value nil. In that situation, the receiver uses the default minimum track image for drawing.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the minimum track image associated with the specified control state.

    Declaration

    Swift

    func minimumTrackImageForState(_ state: UIControlState) -> UIImage?

    Objective-C

    - (UIImage *)minimumTrackImageForState:(UIControlState)state

    Parameters

    state

    The control state whose minimum track image you want. You should specify only one control state value for this parameter.

    Return Value

    The minimum track image associated with the specified state, or nil if no image has been set. This method might also return nil if you specify multiple control states in the state parameter. For a description of track images, see Customizing the Slider’s Appearance.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Assigns a minimum track image to the specified control states.

    Declaration

    Swift

    func setMinimumTrackImage(_ image: UIImage?, forState state: UIControlState)

    Objective-C

    - (void)setMinimumTrackImage:(UIImage *)image forState:(UIControlState)state

    Parameters

    image

    The minimum track image to associate with the specified states.

    state

    The control state with which to associate the image.

    Discussion

    The orientation of the track image must match the orientation of the slider control. To facilitate the stretching of the image to fill the space between the thumb and end point, track images are usually defined in three regions. A stretchable region sits between two end cap regions. The end caps define the portions of the image that remain as is and are not stretched. The stretchable region is a 1-point wide area between the end caps that can be replicated to make the image appear longer.

    To define the end cap sizes for a slider, assign an appropriate value to the image’s leftCapWidth property. For more information about how this value defines the regions of the slider, see the UIImage class.

    Setting a new track image for any state clears any custom tint color you may have provided for minimum track images.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The color used to tint the standard maximum track images.

    Declaration

    Swift

    var maximumTrackTintColor: UIColor?

    Objective-C

    @property(nonatomic, retain) UIColor *maximumTrackTintColor

    Discussion

    Setting this property removes any custom maximum track images associated with the slider.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Contains the maximum track image currently being used to render the receiver. (read-only)

    Declaration

    Swift

    var currentMaximumTrackImage: UIImage! { get }

    Objective-C

    @property(nonatomic, readonly) UIImage *currentMaximumTrackImage

    Discussion

    Sliders can have different track images for different control states. The image associated with this property reflects the maximum track image associated with the currently active control state. To get the maximum track image for a different control state, use the maximumTrackImageForState: method.

    If no custom track images have been set using the setMaximumTrackImage:forState: method, this property contains the value nil. In that situation, the receiver uses the default maximum track image for drawing.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the maximum track image associated with the specified control state.

    Declaration

    Swift

    func maximumTrackImageForState(_ state: UIControlState) -> UIImage?

    Objective-C

    - (UIImage *)maximumTrackImageForState:(UIControlState)state

    Parameters

    state

    The control state whose maximum track image you want. You should specify only one control state value for this parameter.

    Return Value

    The maximum track image associated with the specified state, or nil if an appropriate image could not be retrieved. This method might return nil if you specify multiple control states in the state parameter. For a description of track images, see Customizing the Slider’s Appearance.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Assigns a maximum track image to the specified control states.

    Declaration

    Swift

    func setMaximumTrackImage(_ image: UIImage?, forState state: UIControlState)

    Objective-C

    - (void)setMaximumTrackImage:(UIImage *)image forState:(UIControlState)state

    Parameters

    image

    The maximum track image to associate with the specified states.

    state

    The control state with which to associate the image.

    Discussion

    The orientation of the track image must match the orientation of the slider control. To facilitate the stretching of the image to fill the space between the thumb and end point, track images are usually defined in three regions. A stretchable region sits between two end cap regions. The end caps define the portions of the image that remain as is and are not stretched. The stretchable region is a 1-point wide area between the end caps that can be replicated to make the image appear longer.

    To define the end cap sizes for a slider, assign an appropriate value to the image’s leftCapWidth property. For more information about how this value defines the regions of the slider, see the UIImage class.

    Setting a new track image for any state clears any custom tint color you may have provided for maximum track images.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The color used to tint the standard thumb images.

    Declaration

    Swift

    var thumbTintColor: UIColor?

    Objective-C

    @property(nonatomic, retain) UIColor *thumbTintColor

    Discussion

    Setting this property removes any custom thumb images associated with the slider.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Contains the thumb image currently being used to render the receiver. (read-only)

    Declaration

    Swift

    var currentThumbImage: UIImage? { get }

    Objective-C

    @property(nonatomic, readonly) UIImage *currentThumbImage

    Discussion

    Sliders can have different thumb images for different control states. The image associated with this property reflects the thumb image associated with the currently active control state. To get the thumb image for a different control state, use the thumbImageForState: method.

    If no custom thumb images have been set using the setThumbImage:forState: method, this property contains the value nil. In that situation, the receiver uses the default thumb image for drawing.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the thumb image associated with the specified control state.

    Declaration

    Swift

    func thumbImageForState(_ state: UIControlState) -> UIImage?

    Objective-C

    - (UIImage *)thumbImageForState:(UIControlState)state

    Parameters

    state

    The control state whose thumb image you want. You should specify only one control state value for this parameter.

    Return Value

    The thumb image associated with the specified state, or nil if an appropriate image could not be retrieved. This method might return nil if you specify multiple control states in the state parameter. For a description of track and thumb images, see Customizing the Slider’s Appearance.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Assigns a thumb image to the specified control states.

    Declaration

    Swift

    func setThumbImage(_ image: UIImage?, forState state: UIControlState)

    Objective-C

    - (void)setThumbImage:(UIImage *)image forState:(UIControlState)state

    Parameters

    image

    The thumb image to associate with the specified states.

    state

    The control state with which to associate the image.

    Discussion

    Setting a new thumb image for any state clears any custom tint color you may have provided for thumb images.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the drawing rectangle for the maximum value image.

    Declaration

    Swift

    func maximumValueImageRectForBounds(_ bounds: CGRect) -> CGRect

    Objective-C

    - (CGRect)maximumValueImageRectForBounds:(CGRect)bounds

    Parameters

    bounds

    The bounding rectangle of the receiver.

    Return Value

    The computed drawing rectangle for the image.

    Discussion

    You should not call this method directly. If you want to customize the rectangle in which the maximum value image is drawn, you can override this method and return a different rectangle.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the drawing rectangle for the minimum value image.

    Declaration

    Swift

    func minimumValueImageRectForBounds(_ bounds: CGRect) -> CGRect

    Objective-C

    - (CGRect)minimumValueImageRectForBounds:(CGRect)bounds

    Parameters

    bounds

    The bounding rectangle of the receiver.

    Return Value

    The computed drawing rectangle for the image.

    Discussion

    You should not call this method directly. If you want to customize the rectangle in which the minimum value image is drawn, you can override this method and return a different rectangle.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the drawing rectangle for the slider’s track.

    Declaration

    Swift

    func trackRectForBounds(_ bounds: CGRect) -> CGRect

    Objective-C

    - (CGRect)trackRectForBounds:(CGRect)bounds

    Parameters

    bounds

    The bounding rectangle of the receiver.

    Return Value

    The computed drawing rectangle for the track. This rectangle corresponds to the entire length of the track between the minimum and maximum value images.

    Discussion

    You should not call this method directly. If you want to customize the track rectangle, you can override this method and return a different rectangle. The returned rectangle is used to scale the track and thumb images during drawing.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the drawing rectangle for the slider’s thumb image.

    Declaration

    Swift

    func thumbRectForBounds(_ bounds: CGRect, trackRect rect: CGRect, value value: Float) -> CGRect

    Objective-C

    - (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value

    Parameters

    bounds

    The bounding rectangle of the receiver.

    rect

    The drawing rectangle for the receiver’s track, as returned by the trackRectForBounds: method.

    value

    The current value of the slider.

    Return Value

    The computed drawing rectangle for the thumb image.

    Discussion

    You should not call this method directly. If you want to customize the thumb image’s drawing rectangle, you can override this method and return a different rectangle. The rectangle you return should reflect the size of your thumb image and its current position on the slider’s track.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.