CCButton Class Reference
| Inherits from | CCControl : CCNode : CCResponder : NSObject |
| Declared in | CCButton.h |
Overview
The CCButton represents a button on the screen. The button is presented with a stretchable background image and/or a title label. Different images, colors and opacity can be set for each of the buttons different states.
Methods for setting callbacks for the button is inherited from CCControl through the setTarget:selector: method or the block property.
Tasks
Creating Buttons
-
+ buttonWithTitle: -
+ buttonWithTitle:fontName:fontSize: -
+ buttonWithTitle:spriteFrame: -
+ buttonWithTitle:spriteFrame:highlightedSpriteFrame:disabledSpriteFrame: -
– initWithTitle: -
– initWithTitle:fontName:fontSize: -
– initWithTitle:spriteFrame: -
– initWithTitle:spriteFrame:highlightedSpriteFrame:disabledSpriteFrame: -
– setBackgroundColor:forState: -
– backgroundColorForState: -
– setBackgroundOpacity:forState: -
– backgroundOpacityForState: -
– setColor: -
– setLabelColor:forState: -
– labelColorForState: -
– setLabelOpacity:forState: -
– labelOpacityForState: -
– setBackgroundSpriteFrame:forState: -
– backgroundSpriteFrameForState:
Class Methods
buttonWithTitle:
Creates a new button with a title and no background. Uses default font and font size.
+ (id)buttonWithTitle:(NSString *)titleParameters
- title
The title text of the button.
Return Value
A new button.
Declared In
CCButton.hbuttonWithTitle:fontName:fontSize:
Creates a new button with a title and no background.
+ (id)buttonWithTitle:(NSString *)title fontName:(NSString *)fontName fontSize:(float)sizeParameters
- title
The title text of the button.
- fontName
Name of the TTF font to use for the title label.
- size
Font size for the title label.
Return Value
A new button.
Declared In
CCButton.hbuttonWithTitle:spriteFrame:
Creates a new button with the specified title for the label and sprite frame for its background.
+ (id)buttonWithTitle:(NSString *)title spriteFrame:(CCSpriteFrame *)spriteFrameParameters
- title
The title text of the button.
- spriteFrame
Stretchable background image.
Return Value
A new button.
Declared In
CCButton.hbuttonWithTitle:spriteFrame:highlightedSpriteFrame:disabledSpriteFrame:
Creates a new button with the speicified title for the label, sprite frames for its background in different states.
+ (id)buttonWithTitle:(NSString *)title spriteFrame:(CCSpriteFrame *)spriteFrame highlightedSpriteFrame:(CCSpriteFrame *)highlighted disabledSpriteFrame:(CCSpriteFrame *)disabledParameters
- title
The title text of the button.
- spriteFrame
Stretchable background image for the normal state.
- highlighted
Stretchable background image for the highlighted state.
- disabled
Stretchable background image for the disabled state.
Return Value
A new button.
Declared In
CCButton.hInstance Methods
backgroundColorForState:
Gets the background color for the specified state.
- (CCColor *)backgroundColorForState:(CCControlState)stateParameters
- state
State to get the color for.
Return Value
Background color.
Declared In
CCButton.hbackgroundOpacityForState:
Gets the background opacity for the specified state.
- (CGFloat)backgroundOpacityForState:(CCControlState)stateParameters
- state
State to get the opacity for.
Return Value
Opacity.
Declared In
CCButton.hbackgroundSpriteFrameForState:
Gets the background’s sprite frame for the specified state.
- (CCSpriteFrame *)backgroundSpriteFrameForState:(CCControlState)stateParameters
- state
State to get the sprite frame for.
Return Value
Background sprite frame.
Declared In
CCButton.hinitWithTitle:
Initializes a new button with a title and no background. Uses default font and font size.
- (id)initWithTitle:(NSString *)titleParameters
- title
The title text of the button.
Return Value
A new button.
Declared In
CCButton.hinitWithTitle:fontName:fontSize:
Initializes a new button with a title and no background.
- (id)initWithTitle:(NSString *)title fontName:(NSString *)fontName fontSize:(float)sizeParameters
- title
The title text of the button.
- fontName
Name of the TTF font to use for the title label.
- size
Font size for the title label.
Return Value
A new button.
Declared In
CCButton.hinitWithTitle:spriteFrame:
Initializes a new button with the specified title for the label and sprite frame for its background.
- (id)initWithTitle:(NSString *)title spriteFrame:(CCSpriteFrame *)spriteFrameParameters
- title
The title text of the button.
- spriteFrame
Stretchable background image.
Return Value
A new button.
Declared In
CCButton.hinitWithTitle:spriteFrame:highlightedSpriteFrame:disabledSpriteFrame:
Initializes a new button with the speicified title for the label, sprite frames for its background in different states.
- (id)initWithTitle:(NSString *)title spriteFrame:(CCSpriteFrame *)spriteFrame highlightedSpriteFrame:(CCSpriteFrame *)highlighted disabledSpriteFrame:(CCSpriteFrame *)disabledParameters
- title
The title text of the button.
- spriteFrame
Stretchable background image for the normal state.
- highlighted
Stretchable background image for the highlighted state.
- disabled
Stretchable background image for the disabled state.
Return Value
A new button.
Declared In
CCButton.hlabelColorForState:
Gets the label’s color for the specified state.
- (CCColor *)labelColorForState:(CCControlState)stateParameters
- state
State to get the color for.
Return Value
Label color.
Declared In
CCButton.hlabelOpacityForState:
Gets the label’s opacity for the specified state.
- (CGFloat)labelOpacityForState:(CCControlState)stateParameters
- state
State to get the opacity for.
Return Value
Label opacity.
Declared In
CCButton.hsetBackgroundColor:forState:
Sets the background color for the specified state. The color is multiplied into the background sprite frame.
- (void)setBackgroundColor:(CCColor *)color forState:(CCControlState)stateParameters
- color
Color applied to background image.
- state
State to apply the color to.
Declared In
CCButton.hsetBackgroundOpacity:forState:
Sets the background’s opacity for the specified state.
- (void)setBackgroundOpacity:(CGFloat)opacity forState:(CCControlState)stateParameters
- opacity
Opacity to apply to the background image
- state
State to apply the opacity to.
Declared In
CCButton.hsetBackgroundSpriteFrame: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 NULL no background will be drawn.
- (void)setBackgroundSpriteFrame:(CCSpriteFrame *)spriteFrame forState:(CCControlState)stateParameters
- spriteFrame
Sprite frame to use for drawing the background.
- state
State to set the background for.
Declared In
CCButton.hsetColor:
Will set the label’s color for the normal state.
- (void)setColor:(CCColor *)colorParameters
- color
Color applied to the label.
Declared In
CCButton.h