CCControlButton Class Reference
Inherits from | CCControl : CCLayer |
Declared in | CCControlButton.h |
Overview
Button control for Cocos2D.
A button intercepts touch events and sends an action message to a target object when tapped. Methods for setting the target and action are inherited from CCControl.
Tasks
Other Methods
-
adjustBackgroundImage
Adjust the background image. YES by default. If the property is set to NO, the background will use the preferred size of the background image.
property -
currentTitle
The current title that is displayed on the button.
property -
currentTitleColor
The current color used to display the title.
property -
titleLabel
The current title label.
property -
backgroundSprite
The current background sprite.
property -
preferredSize
The preferred size of the button, if label is larger it will be expanded.
property -
zoomOnTouchDown
Scale the button up when it is touched, default is YES.
property -
labelAnchorPoint
The anchorPoint of the label, default is (0.5,0.5)
property -
marginTB
The margins. By default the values of marginLR and marginTB are, respectively, equals to CCControlButtonMarginLR and CCControlButtonMarginTB.
property
Creating Buttons
-
– initWithLabel:backgroundSprite:
Initializes a button with a label in foreground and a sprite in background.
-
+ buttonWithLabel:backgroundSprite:
Creates a button with a label in foreground and a sprite in background.
-
– initWithTitle:fontName:fontSize:
Initializes a button with a title, a font name and a font size for the label in foreground.
-
+ buttonWithTitle:fontName:fontSize:
Creates a button with a title, a font name and a font size for the label in foreground.
-
– initWithBackgroundSprite:
Initializes a button with a sprite in background.
-
+ buttonWithBackgroundSprite:
Creates a button with a sprite in background.
Configuring/Getting the Button Title
-
– titleForState:
Returns the title used for a state.
-
– setTitle:forState:
Sets the title string to use for the specified state. If a property is not specified for a state, the default is to use the CCButtonStateNormal value.
-
– titleColorForState:
Returns the title color used for a state.
-
– setTitleColor:forState:
Sets the color of the title to use for the specified state.
-
– titleLabelForState:
Returns the title label used for a state.
-
– setTitleLabel:forState:
Sets the title label to use for the specified state. If a property is not specified for a state, the default is to use the CCButtonStateNormal value.
-
– setTitleBMFont:forState:
Sets the font of the label, changes the label to a CCLabelBMFont if neccessary.
-
– setTitleTTF:forState:
Sets the font of the label, changes the label to a CCLabelTTF if neccessary.
-
– titleTTFForState:
Returns the name of the TTF font used by the label, or NULL if the label is a CCLabelBMFont.
-
– setTitleTTFSize:forState:
Sets the font size of the label, will only work with ttf labels.
-
– titleTTFSizeForState:
Returns the sizer of the TTF font used by the label, or 0 if the label is a CCLabelBMFont.
Configuring/Getting Button Background Presentation
-
– backgroundSpriteForState:
Returns the background sprite used for a state.
-
– setBackgroundSprite:forState:
Sets the background sprite to use for the specified button state.
-
– setBackgroundSpriteFrame:forState:
Sets the background spriteFrame to use for the specified button state.
Properties
adjustBackgroundImage
Adjust the background image. YES by default. If the property is set to NO, the background will use the preferred size of the background image.
@property (nonatomic, getter=doesAdjustBackgroundImage) BOOL adjustBackgroundImage
Discussion
Adjust the background image. YES by default. If the property is set to NO, the background will use the preferred size of the background image.
Declared In
CCControlButton.h
backgroundSprite
The current background sprite.
@property (nonatomic, strong) CCScale9Sprite *backgroundSprite
Discussion
The current background sprite.
Declared In
CCControlButton.h
currentTitle
The current title that is displayed on the button.
@property (nonatomic, readonly, strong) NSString *currentTitle
Discussion
The current title that is displayed on the button.
Declared In
CCControlButton.h
currentTitleColor
The current color used to display the title.
@property (nonatomic, readonly, assign) ccColor3B currentTitleColor
Discussion
The current color used to display the title.
Declared In
CCControlButton.h
labelAnchorPoint
The anchorPoint of the label, default is (0.5,0.5)
@property (nonatomic, assign) CGPoint labelAnchorPoint
Discussion
The anchorPoint of the label, default is (0.5,0.5)
Declared In
CCControlButton.h
marginTB
The margins. By default the values of marginLR and marginTB are, respectively, equals to CCControlButtonMarginLR and CCControlButtonMarginTB.
@property (nonatomic, assign) float marginLR , marginTB
Discussion
The margins. By default the values of marginLR and marginTB are, respectively, equals to CCControlButtonMarginLR and CCControlButtonMarginTB.
Declared In
CCControlButton.h
preferredSize
The preferred size of the button, if label is larger it will be expanded.
@property (nonatomic, assign) CGSize preferredSize
Discussion
The preferred size of the button, if label is larger it will be expanded.
Declared In
CCControlButton.h
Class Methods
buttonWithBackgroundSprite:
Creates a button with a sprite in background.
+ (id)buttonWithBackgroundSprite:(CCScale9Sprite *)backgroundsprite
Discussion
Creates a button with a sprite in background.
See Also
Declared In
CCControlButton.h
buttonWithLabel:backgroundSprite:
Creates a button with a label in foreground and a sprite in background.
+ (id)buttonWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol> *)label backgroundSprite:(CCScale9Sprite *)backgroundsprite
Discussion
Creates a button with a label in foreground and a sprite in background.
See Also
Declared In
CCControlButton.h
buttonWithTitle:fontName:fontSize:
Creates a button with a title, a font name and a font size for the label in foreground.
+ (id)buttonWithTitle:(NSString *)title fontName:(NSString *)fontName fontSize:(NSUInteger)fontsize
Discussion
Creates a button with a title, a font name and a font size for the label in foreground.
See Also
Declared In
CCControlButton.h
Instance Methods
backgroundSpriteForState:
Returns the background sprite used for a state.
- (CCScale9Sprite *)backgroundSpriteForState:(CCControlState)state
Parameters
- state
The state that uses the background sprite. Possible values are described in “CCControlState”.
Discussion
Returns the background sprite used for a state.
Declared In
CCControlButton.h
initWithBackgroundSprite:
Initializes a button with a sprite in background.
- (id)initWithBackgroundSprite:(CCScale9Sprite *)backgroundsprite
Parameters
- backgroundsprite
CCScale9Sprite, that is used as a background.
Discussion
Initializes a button with a sprite in background.
Declared In
CCControlButton.h
initWithLabel:backgroundSprite:
Initializes a button with a label in foreground and a sprite in background.
- (id)initWithLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol> *)label backgroundSprite:(CCScale9Sprite *)backgroundsprite
Parameters
- label
label, that is used as a foreground title.
- backgroundsprite
CCScale9Sprite, that is used as a background.
Discussion
Initializes a button with a label in foreground and a sprite in background.
Declared In
CCControlButton.h
initWithTitle:fontName:fontSize:
Initializes a button with a title, a font name and a font size for the label in foreground.
- (id)initWithTitle:(NSString *)title fontName:(NSString *)fontName fontSize:(NSUInteger)fontsize
Parameters
- title
Title displayed on the button.
- fontName
Font name to use to render the title.
- fontSize
Font name to use to render the title.
Discussion
Initializes a button with a title, a font name and a font size for the label in foreground.
Declared In
CCControlButton.h
setBackgroundSprite:forState:
Sets the background sprite to use for the specified button state.
- (void)setBackgroundSprite:(CCScale9Sprite *)sprite forState:(CCControlState)state
Parameters
- sprite
The background sprite to use for the specified state.
- state
The state that uses the specified image. The values are described in “CCControlState”.
Discussion
Sets the background sprite to use for the specified button state.
Declared In
CCControlButton.h
setBackgroundSpriteFrame:forState:
Sets the background spriteFrame to use for the specified button state.
- (void)setBackgroundSpriteFrame:(CCSpriteFrame *)spriteFrame forState:(CCControlState)state
Parameters
- spriteFrame
The background spriteFrame to use for the specified state.
- state
The state that uses the specified image. The values are described in “CCControlState”.
Discussion
Sets the background spriteFrame to use for the specified button state.
Declared In
CCControlButton.h
setTitle:forState:
Sets the title string to use for the specified state. If a property is not specified for a state, the default is to use the CCButtonStateNormal value.
- (void)setTitle:(NSString *)title forState:(CCControlState)state
Parameters
- title
The title string to use for the specified state.
- state
The state that uses the specified title. The values are described in “CCControlState”.
Discussion
Sets the title string to use for the specified state. If a property is not specified for a state, the default is to use the CCButtonStateNormal value.
Declared In
CCControlButton.h
setTitleBMFont:forState:
Sets the font of the label, changes the label to a CCLabelBMFont if neccessary.
- (void)setTitleBMFont:(NSString *)fntFile forState:(CCControlState)state
Parameters
- fntFile
The name of the font to change to
- state
The state that uses the specified fntFile. The values are described in “CCControlState”.
Discussion
Sets the font of the label, changes the label to a CCLabelBMFont if neccessary.
Declared In
CCControlButton.h
setTitleColor:forState:
Sets the color of the title to use for the specified state.
- (void)setTitleColor:(ccColor3B)color forState:(CCControlState)state
Parameters
- color
The color of the title to use for the specified state.
- state
The state that uses the specified color. The values are described in “CCControlState”.
Discussion
Sets the color of the title to use for the specified state.
Declared In
CCControlButton.h
setTitleLabel:forState:
Sets the title label to use for the specified state. If a property is not specified for a state, the default is to use the CCButtonStateNormal value.
- (void)setTitleLabel:(CCNode<CCLabelProtocol,CCRGBAProtocol> *)label forState:(CCControlState)state
Parameters
- state
The state that uses the specified title. The values are described in “CCControlState”.
- title
The title label to use for the specified state.
Discussion
Sets the title label to use for the specified state. If a property is not specified for a state, the default is to use the CCButtonStateNormal value.
Declared In
CCControlButton.h
setTitleTTF:forState:
Sets the font of the label, changes the label to a CCLabelTTF if neccessary.
- (void)setTitleTTF:(NSString *)fontName forState:(CCControlState)state
Parameters
- state
The state that uses the specified fntFile. The values are described in “CCControlState”.
- fntFile
The name of the font to change to
Discussion
Sets the font of the label, changes the label to a CCLabelTTF if neccessary.
Declared In
CCControlButton.h
setTitleTTFSize:forState:
Sets the font size of the label, will only work with ttf labels.
- (void)setTitleTTFSize:(float)size forState:(CCControlState)state
Parameters
- state
The state that uses the specified fntFile. The values are described in “CCControlState”.
- fntFile
The name of the font to change to
Discussion
Sets the font size of the label, will only work with ttf labels.
Declared In
CCControlButton.h
titleColorForState:
Returns the title color used for a state.
- (ccColor3B)titleColorForState:(CCControlState)state
Parameters
- state
The state that uses the specified color. The values are described in “CCControlState”.
Return Value
The color of the title for the specified state.
Discussion
Returns the title color used for a state.
Declared In
CCControlButton.h
titleForState:
Returns the title used for a state.
- (NSString *)titleForState:(CCControlState)state
Parameters
- state
The state that uses the title. Possible values are described in “CCControlState”.
Return Value
The title for the specified state.
Discussion
Returns the title used for a state.
Declared In
CCControlButton.h
titleLabelForState:
Returns the title label used for a state.
- (CCNode<CCLabelProtocol,CCRGBAProtocol> *)titleLabelForState:(CCControlState)state
Parameters
- state
The state that uses the title label. Possible values are described in “CCControlState”.
Discussion
Returns the title label used for a state.
Declared In
CCControlButton.h
titleTTFForState:
Returns the name of the TTF font used by the label, or NULL if the label is a CCLabelBMFont.
- (NSString *)titleTTFForState:(CCControlState)state
Parameters
- state
The state that uses the specified font. The values are described in “CCControlState”.
Discussion
Returns the name of the TTF font used by the label, or NULL if the label is a CCLabelBMFont.
Declared In
CCControlButton.h
titleTTFSizeForState:
Returns the sizer of the TTF font used by the label, or 0 if the label is a CCLabelBMFont.
- (float)titleTTFSizeForState:(CCControlState)state
Parameters
- state
The state that uses the specified font. The values are described in “CCControlState”.
Discussion
Returns the sizer of the TTF font used by the label, or 0 if the label is a CCLabelBMFont.
Declared In
CCControlButton.h