Vous êtes sur la page 1sur 21

UISlider Class Reference

Contents

UISlider Class Reference 4


Overview 4 Customizing the Sliders Appearance 4 Tasks 5 Accessing the Sliders Value 5 Accessing the Sliders Value Limits 5 Modifying the Sliders Behavior 5 Changing the Sliders Appearance 6 Overrides for Subclasses 7 Properties 7 continuous 7 currentMaximumTrackImage 7 currentMinimumTrackImage 8 currentThumbImage 9 maximumTrackTintColor 9 maximumValue 10 maximumValueImage 10 minimumTrackTintColor 10 minimumValue 11 minimumValueImage 11 thumbTintColor 12 value 12 Instance Methods 13 maximumTrackImageForState: 13 maximumValueImageRectForBounds: 13 minimumTrackImageForState: 14 minimumValueImageRectForBounds: 14 setMaximumTrackImage:forState: 15 setMinimumTrackImage:forState: 16 setThumbImage:forState: 16 setValue:animated: 17 thumbImageForState: 18 thumbRectForBounds:trackRect:value: 18 trackRectForBounds: 19

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

Contents

Document Revision History 20

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

UISlider Class Reference

Inherits from Conforms to

UIControl : UIView : UIResponder : NSObject NSCoding NSCoding (UIView) UIAppearance (UIView) UIAppearanceContainer (UIView) NSObject (NSObject)

Framework Availability Declared in

/System/Library/Frameworks/UIKit.framework Available in iOS 2.0 and later. UISlider.h

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.

Customizing the Sliders Appearance


The most common way to customize the sliders appearance is to provide custom minimum and maximum value images. These images sit at either end of the slider control and indicate which value that end of the slider represents. For example, a slider used to control volume might display a small speaker with no sound waves emanating from it for the minimum value and display a large speaker with many sound waves emanating from it for the maximum value. The bar on which the thumb rides is referred to as the sliders track. Slider controls draw the track using two distinct images, which are customizable. The region between the thumb and the end of the track associated with the sliders minimum value is drawn using the minimum track image. The region between the thumb and the end of the track associated with the sliders maximum value is drawn using the maximum track image. Different track images are used in order to provide context as to which end contains the minimum value. For example, the minimum track image typically contains a blue highlight while the maximum track image contains

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

UISlider Class Reference Tasks

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

Contains the receivers current value.


setValue:animated:

(page 17) Sets the receivers current value, allowing you to animate the change visually.

Accessing the Sliders Value Limits


minimumValue (page 11)

property

Contains the minimum value of the receiver.


maximumValue (page 10)

property

Contains the maximum value of the receiver.

Modifying the Sliders Behavior


continuous (page 7)

property

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

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

UISlider Class Reference Tasks

Changing the Sliders Appearance


minimumValueImage (page 11)

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

The color used to tint the standard minimum track images.


currentMinimumTrackImage (page 8)

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)

The color used to tint the standard maximum track images.


currentMaximumTrackImage (page 7)

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:

thumbTintColor (page 12)

The color used to tint the standard thumb images.


currentThumbImage (page 9)

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:

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

UISlider Class Reference Properties

Overrides for Subclasses


maximumValueImageRectForBounds:

(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)

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

UISlider Class Reference Properties

@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. 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:

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

UISlider Class Reference Properties

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:

(page 18) (page 16)

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

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

UISlider Class Reference Properties

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.

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

10

UISlider Class Reference Properties

@property(nonatomic, retain) UIColor *minimumTrackTintColor

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.

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

11

UISlider Class Reference Properties

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

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

12

UISlider Class Reference Instance Methods

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.

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

13

UISlider Class Reference Instance Methods

Availability Available in iOS 2.0 and later. Declared in


UISlider.h

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

The bounding rectangle of the receiver.

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

14

UISlider Class Reference Instance Methods

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 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 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)

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

15

UISlider Class Reference Instance Methods

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 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 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

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

16

UISlider Class Reference Instance Methods

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. 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

The new value to assign to the value property


animated

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)

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

17

UISlider Class Reference Instance Methods

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 bounding rectangle of the receiver.


rect

The drawing rectangle for the receivers track, as returned by the trackRectForBounds: (page 19) method.
value

The current value of the slider.

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

18

UISlider Class Reference Instance Methods

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

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

19

Document Revision History

This table describes the changes to UISlider Class Reference .

Date 2011-10-12 2008-06-16

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.

2011-10-12 | 2011 Apple Inc. All Rights Reserved.

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.

Vous aimerez peut-être aussi