CCSlider Class Reference

Inherits from CCControl : CCNode : CCResponder : NSObject
Declared in CCSlider.h

Overview

A slider is a control where the user drags a handle to set a slider value in the range 0.0 to 1.0.

The slider orientation is horizontal, but it can be changed to vertical (or any) orientation by changing the slider’s rotation property.

The slider automatically adds a background (the slider range) CCSprite9Slice and a handle CCSprite (what the user grabs). You should not remove these nodes nor should you add custom nodes to the slider.

Creating a Slider

– initWithBackground:andHandleImage:

Initializes a new slider with a specified sprite frames for its background and handle.

- (id)initWithBackground:(CCSpriteFrame *)background andHandleImage:(CCSpriteFrame *)handle

Parameters

background

Stretchable background image which represents the track bar for the normal state.

handle

Handle image for the normal state.

See Also

Declared In

CCSlider.h

Slider Child Nodes

  background

The background sprite.

@property (nonatomic, readonly) CCSprite9Slice *background

See Also

Declared In

CCSlider.h

  handle

The handle sprite.

@property (nonatomic, readonly) CCSprite *handle

See Also

Declared In

CCSlider.h

Slider Value

  sliderValue

Contains the slider’s current value. Setting this property causes the receiver to redraw itself using the new value. The default value of this property is 0.0.

@property (nonatomic, assign) float sliderValue

Discussion

Note: If you try to set a value below 0.0 or above 1.0, the value is clamped to 0.0 or 1.0 respectively.

Declared In

CCSlider.h

Customizing Slider Appearance

– setBackgroundSpriteFrame:forState:

Sets the background’s sprite frame for the specified state. The sprite frame will be stretched to the preferred size of the label. If set to nil no background will be drawn.

- (void)setBackgroundSpriteFrame:(CCSpriteFrame *)spriteFrame forState:(CCControlState)state

Parameters

spriteFrame

Sprite frame to use for drawing the background.

state

State to set the background for.

Declared In

CCSlider.h

– backgroundSpriteFrameForState:

Gets the background’s sprite frame for the specified state.

- (CCSpriteFrame *)backgroundSpriteFrameForState:(CCControlState)state

Parameters

state

State to get the sprite frame for.

Return Value

Background sprite frame.

Declared In

CCSlider.h

– setHandleSpriteFrame:forState:

Sets the handle’s sprite frame for the specified state. If set to nil no handle will be drawn.

- (void)setHandleSpriteFrame:(CCSpriteFrame *)spriteFrame forState:(CCControlState)state

Parameters

spriteFrame

Sprite frame to use for drawing the handle.

state

State to set the handle for.

Declared In

CCSlider.h

– handleSpriteFrameForState:

Gets the handle’s sprite frame for the specified state.

- (CCSpriteFrame *)handleSpriteFrameForState:(CCControlState)state

Parameters

state

State to get the sprite frame for.

Return Value

Handle sprite frame.

Declared In

CCSlider.h