CCControlSwitch Class Reference
Inherits from | CCControl : CCLayer |
Declared in | CCControlSwitch.h |
Overview
CCControlSwitch is a switch control for Cocos2D.
The CCControlSwitch class is useful to create and manage On/Off buttons, like for example, in the option menus for volume as example.
The CCControlSwitch class declares a property and a method to control its on/off state. As with CCControlSlider, when the user manipulates the switch control (“flips” it) a CCControlEventValueChanged event is generated, which results in the control (if properly configured) sending an action message.
Tasks
Creating Switches
-
– initWithMaskSprite:onSprite:offSprite:thumbSprite:
Initializes a switch with a mask sprite, on/off sprites for on/off states and a thumb sprite.
-
+ switchWithMaskSprite:onSprite:offSprite:thumbSprite:
Creates a switch with a mask sprite, on/off sprites for on/off states and a thumb sprite.
-
+ switchWithMaskFile:onFile:offFile:thumbFile:
Creates a switch with a mask, the on/off and a thumb filenames.
-
– initWithMaskSprite:onSprite:offSprite:thumbSprite:onLabel:offLabel:
Initializes a switch with a mask sprite, on/off sprites for on/off states, a thumb sprite and an on/off labels.
-
+ switchWithMaskSprite:onSprite:offSprite:thumbSprite:onLabel:offLabel:
Creates a switch with a mask sprite, on/off sprites for on/off states, a thumb sprite and an on/off labels.
-
+ switchWithMaskFile:onFile:offFile:thumbFile:onTitle:offTitle:
Creates a switch with a mask, the on/off and a thumb filenames and the on/off titles.
Setting the Off/On State
-
on
A Boolean value that determines the off/on state of the switch.
property -
– setOn:animated:
Set the state of the switch to On or Off, optionally animating the transition.
Customizing the Appearance of the Switch
-
onThumbTintColor
The color used to tint the appearance of the thumb when the switch is pushed.
property
Properties
Class Methods
switchWithMaskFile:onFile:offFile:thumbFile:
Creates a switch with a mask, the on/off and a thumb filenames.
+ (id)switchWithMaskFile:(NSString *)maskFile onFile:(NSString *)onFile offFile:(NSString *)offFile thumbFile:(NSString *)thumbFile
Discussion
Creates a switch with a mask, the on/off and a thumb filenames.
Declared In
CCControlSwitch.h
switchWithMaskFile:onFile:offFile:thumbFile:onTitle:offTitle:
Creates a switch with a mask, the on/off and a thumb filenames and the on/off titles.
+ (id)switchWithMaskFile:(NSString *)maskFile onFile:(NSString *)onFile offFile:(NSString *)offFile thumbFile:(NSString *)thumbFile onTitle:(NSString *)onTitle offTitle:(NSString *)offTitle
Discussion
Creates a switch with a mask, the on/off and a thumb filenames and the on/off titles.
Declared In
CCControlSwitch.h
switchWithMaskSprite:onSprite:offSprite:thumbSprite:
Creates a switch with a mask sprite, on/off sprites for on/off states and a thumb sprite.
+ (id)switchWithMaskSprite:(CCSprite *)maskSprite onSprite:(CCSprite *)onSprite offSprite:(CCSprite *)offSprite thumbSprite:(CCSprite *)thumbSprite
Discussion
Creates a switch with a mask sprite, on/off sprites for on/off states and a thumb sprite.
Declared In
CCControlSwitch.h
switchWithMaskSprite:onSprite:offSprite:thumbSprite:onLabel:offLabel:
Creates a switch with a mask sprite, on/off sprites for on/off states, a thumb sprite and an on/off labels.
+ (id)switchWithMaskSprite:(CCSprite *)maskSprite onSprite:(CCSprite *)onSprite offSprite:(CCSprite *)offSprite thumbSprite:(CCSprite *)thumbSprite onLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol> *)onLabel offLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol> *)offLabel
Discussion
Creates a switch with a mask sprite, on/off sprites for on/off states, a thumb sprite and an on/off labels.
Declared In
CCControlSwitch.h
Instance Methods
initWithMaskSprite:onSprite:offSprite:thumbSprite:
Initializes a switch with a mask sprite, on/off sprites for on/off states and a thumb sprite.
- (id)initWithMaskSprite:(CCSprite *)maskSprite onSprite:(CCSprite *)onSprite offSprite:(CCSprite *)offSprite thumbSprite:(CCSprite *)thumbSprite
Parameters
- maskSprite
The sprite used as mask to hide on/off sprites.
- offSprite
The sprite displayed when the switch is in the off position.
- thumbSprite
The sprite used for the thumb.
Discussion
Initializes a switch with a mask sprite, on/off sprites for on/off states and a thumb sprite.
Declared In
CCControlSwitch.h
initWithMaskSprite:onSprite:offSprite:thumbSprite:onLabel:offLabel:
Initializes a switch with a mask sprite, on/off sprites for on/off states, a thumb sprite and an on/off labels.
- (id)initWithMaskSprite:(CCSprite *)maskSprite onSprite:(CCSprite *)onSprite offSprite:(CCSprite *)offSprite thumbSprite:(CCSprite *)thumbSprite onLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol> *)onLabel offLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol> *)offLabel
Parameters
- maskSprite
The sprite used as mask to hide on/off sprites.
- offSprite
The sprite displayed when the switch is in the off position.
- thumbSprite
The sprite used for the thumb.
- offLabel
The label displayed over the offSprite when the switch is in the off position.
Discussion
Initializes a switch with a mask sprite, on/off sprites for on/off states, a thumb sprite and an on/off labels.
Declared In
CCControlSwitch.h
setOn:animated:
Set the state of the switch to On or Off, optionally animating the transition.
- (void)setOn:(BOOL)isOn animated:(BOOL)animated
Parameters
- isOn
YES if the switch should be turned to the On position; NO if it should be turned to the Off position. If the switch is already in the designated position, nothing happens.
- animated
YES to animate the “flipping” of the switch; otherwise NO.
Declared In
CCControlSwitch.h