Académique Documents
Professionnel Documents
Culture Documents
Contents
Contents
UIControl : UIView : UIResponder : NSObject NSCoding NSCoding (UIView) UIAppearance (UIView) UIAppearanceContainer (UIView) NSObject (NSObject)
Overview
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.
a white highlight. You can assign different tint colors for all of the standard parts provided by the slider, or you customize the appearance further by assigning different pairs of track images to each of the control states of the slider. Assigning different images to each state lets you customize the appearance of the slider when it is enabled, disabled, highlighted, and so on. In addition to customizing the track images, you can also customize the appearance of the thumb itself. Like the track images, you can assign different thumb images to each control state of the slider. Note: The slider control provides a set of default images for both the track and thumb. If you do not specify any custom images, those images are used automatically.
Tasks
Accessing the Sliders Value
value (page 12)
property
(page 17) Sets the receivers current value, allowing you to animate the change visually.
property
property
property
Contains a Boolean value indicating whether changes in the sliders value generate continuous update events.
property
Contains the image that is drawn on the side of the slider representing the minimum value.
maximumValueImage (page 10)
property
Contains the image that is drawn on the side of the slider representing the maximum value.
minimumTrackTintColor (page 10)
property
property
Contains the minimum track image currently being used to render the receiver. (read-only)
minimumTrackImageForState:
(page 14) Returns the minimum track image associated with the specified control state. (page 16) Assigns a minimum track image to the specified control states. property
setMinimumTrackImage:forState:
maximumTrackTintColor (page 9)
property
Contains the maximum track image currently being used to render the receiver. (read-only)
maximumTrackImageForState:
(page 13) Returns the maximum track image associated with the specified control state. (page 15) Assigns a maximum track image to the specified control states. property
setMaximumTrackImage:forState:
property
Contains the thumb image currently being used to render the receiver. (read-only)
thumbImageForState:
(page 18) Returns the thumb image associated with the specified control state. (page 16) Assigns a thumb image to the specified control states.
setThumbImage:forState:
(page 13) Returns the drawing rectangle for the maximum value image. (page 14) Returns the drawing rectangle for the minimum value image. (page 19) Returns the drawing rectangle for the sliders track. (page 18) Returns the drawing rectangle for the sliders thumb image.
minimumValueImageRectForBounds:
trackRectForBounds:
thumbRectForBounds:trackRect:value:
Properties
continuous
Contains a Boolean value indicating whether changes in the sliders value generate continuous update events.
@property(nonatomic, getter=isContinuous) BOOL continuous
Discussion If YES, the slider sends update events continuously to the associated targets action method. If NO, the slider only sends an action event when the user releases the sliders thumb control to set the final value. The default value of this property is YES. Availability Available in iOS 2.0 and later. Declared in
UISlider.h
currentMaximumTrackImage
Contains the maximum track image currently being used to render the receiver. (read-only)
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. Availability Available in iOS 2.0 and later. See Also (page 13) setMaximumTrackImage:forState: (page 15)
maximumTrackImageForState:
Declared in
UISlider.h
currentMinimumTrackImage
Contains the minimum track image currently being used to render the receiver. (read-only)
@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. Availability Available in iOS 2.0 and later. See Also (page 14) setMinimumTrackImage:forState: (page 16)
minimumTrackImageForState:
Declared in
UISlider.h
currentThumbImage
Contains the thumb image currently being used to render the receiver. (read-only)
@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. Availability Available in iOS 2.0 and later. See Also
thumbImageForState: setThumbImage:forState:
Declared in
UISlider.h
maximumTrackTintColor
The color used to tint the standard maximum track images.
@property(nonatomic, retain) UIColor *maximumTrackTintColor
Discussion Setting this property removes any custom maximum track images associated with the slider. Availability Available in iOS 5.0 and later. Declared in
UISlider.h
maximumValue
Contains the maximum value of the receiver.
@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. Availability Available in iOS 2.0 and later. Declared in
UISlider.h
maximumValueImage
Contains the image that is drawn on the side of the slider representing the maximum value.
@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 receivers track is lengthened or shortened as needed to accommodate the image in its bounding rectangle. This default value of this property is nil. Availability Available in iOS 2.0 and later. Declared in
UISlider.h
minimumTrackTintColor
The color used to tint the standard minimum track images.
10
Discussion Setting this property removes any custom minimum track images associated with the slider. Availability Available in iOS 5.0 and later. Declared in
UISlider.h
minimumValue
Contains the minimum value of the receiver.
@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. Availability Available in iOS 2.0 and later. Declared in
UISlider.h
minimumValueImage
Contains the image that is drawn on the side of the slider representing the minimum value.
@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 receivers track is lengthened or shortened as needed to accommodate the image in its bounding rectangle. This default value of this property is nil. Availability Available in iOS 2.0 and later.
11
Declared in
UISlider.h
thumbTintColor
The color used to tint the standard thumb images.
@property(nonatomic, retain) UIColor *thumbTintColor
Discussion Setting this property removes any custom thumb images associated with the slider. Availability Available in iOS 5.0 and later. Declared in
UISlider.h
value
Contains the receivers current value.
@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. Availability Available in iOS 2.0 and later. See Also
setValue:animated:
(page 17)
Declared in
UISlider.h
12
Instance Methods
maximumTrackImageForState:
Returns the maximum track image associated with the specified control state.
- (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 Sliders Appearance (page 4). Availability Available in iOS 2.0 and later. See Also
setMaximumTrackImage:forState:
(page 15)
Declared in
UISlider.h
maximumValueImageRectForBounds:
Returns the drawing rectangle for the maximum value image.
- (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.
13
minimumTrackImageForState:
Returns the minimum track image associated with the specified control state.
- (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 Sliders Appearance (page 4). Availability Available in iOS 2.0 and later. See Also
setMinimumTrackImage:forState:
(page 16)
Declared in
UISlider.h
minimumValueImageRectForBounds:
Returns the drawing rectangle for the minimum value image.
- (CGRect)minimumValueImageRectForBounds:(CGRect)bounds
Parameters
bounds
14
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. Availability Available in iOS 2.0 and later. Declared in
UISlider.h
setMaximumTrackImage:forState:
Assigns a maximum track image to the specified control states.
- (void)setMaximumTrackImage:(UIImage *)image forState:(UIControlState)state
Parameters
image
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 images 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. Availability Available in iOS 2.0 and later. See Also
maximumTrackImageForState:
(page 13)
15
Declared in
UISlider.h
setMinimumTrackImage:forState:
Assigns a minimum track image to the specified control states.
- (void)setMinimumTrackImage:(UIImage *)image forState:(UIControlState)state
Parameters
image
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 images 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. Availability Available in iOS 2.0 and later. Declared in
UISlider.h
setThumbImage:forState:
Assigns a thumb image to the specified control states.
- (void)setThumbImage:(UIImage *)image forState:(UIControlState)state
16
Parameters
image
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. Availability Available in iOS 2.0 and later. See Also
thumbImageForState:
(page 18)
Declared in
UISlider.h
setValue:animated:
Sets the receivers current value, allowing you to animate the change visually.
- (void)setValue:(float)value animated:(BOOL)animated
Parameters
value
Specify YES to animate the change in value when the receiver is redrawn; otherwise, specify NO 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. Availability Available in iOS 2.0 and later. See Also
@property value (page 12)
17
Declared in
UISlider.h
thumbImageForState:
Returns the thumb image associated with the specified control state.
- (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 Sliders Appearance (page 4). Availability Available in iOS 2.0 and later. See Also
setThumbImage:forState:
(page 16)
Declared in
UISlider.h
thumbRectForBounds:trackRect:value:
Returns the drawing rectangle for the sliders thumb image.
- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value
Parameters
bounds
The drawing rectangle for the receivers track, as returned by the trackRectForBounds: (page 19) method.
value
18
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 images 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 sliders track. Availability Available in iOS 2.0 and later. Declared in
UISlider.h
trackRectForBounds:
Returns the drawing rectangle for the sliders track.
- (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. Availability Available in iOS 2.0 and later. Declared in
UISlider.h
19
Notes Updated for iOS 5. New document that describes the class implementing sliders--visual controls used to select a single value from a continuous range of values.
20
Apple Inc. 2011 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or otherwise, without prior written permission of Apple Inc., with the following exceptions: Any person is hereby authorized to store documentation on a single computer for personal use only and to print copies of documentation for personal use provided that the documentation contains Apples copyright notice. No licenses, express or implied, are granted with respect to any of the technology described in this document. Apple retains all intellectual property rights associated with the technology described in this document. This document is intended to assist application developers to develop applications only for Apple-labeled computers. Apple Inc. 1 Infinite Loop Cupertino, CA 95014 408-996-1010 Apple and the Apple logo are trademarks of Apple Inc., registered in the U.S. and other countries. iOS is a trademark or registered trademark of Cisco in the U.S. and other countries and is used under license.
Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED AS IS, AND YOU, THE READER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY. IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS DOCUMENT, even if advised of the possibility of such damages. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make any modification, extension, or addition to this warranty. Some states do not allow the exclusion or limitation of implied warranties or liability for incidental or consequential damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state.