CCTextField Class Reference
Inherits from | CCControl : CCNode : CCResponder : NSObject |
---|---|
Conforms to | CCPlatformTextFieldDelegate |
Declared in | CCTextField.h |
Overview
A text field is used for editing text. It is implemented by encapsulating the platform’s native text field (NSTextField on Mac and UITextField on iOS. An action callback will be sent when the user is done editing the text (clicks/taps outside) or when the return key is pressed.
A CCSprite9Slice is used a the text field’s background image.
Note: The native text field is only translated (positioned), no other transformations (rotation, scale) are applied. The text field may not be displayed correctly if the node is rotated, scaled, skewed.
Warning: Since the text field is a native UI control, it will always be drawn on top of everything that Cocos2D draws. That means you can’t have another node (ie a sprite) partially or entirely drawn above the text field.
Creating a Text Field
+ textFieldWithSpriteFrame:
Creates a new text field with the specified sprite frame used as its background.
+ (id)textFieldWithSpriteFrame:(CCSpriteFrame *)frame
Parameters
frame |
Sprite frame to use as the text fields background. |
---|
Return Value
Returns a new text field.
Declared In
CCTextField.h
– initWithSpriteFrame:
Initializes a text field with the specified sprite frame used as its background.
- (id)initWithSpriteFrame:(CCSpriteFrame *)frame
Parameters
frame |
Sprite frame to use as the text fields background. |
---|
Return Value
Returns a new text field.
Declared In
CCTextField.h
Accessing the Platform-Specific Text Field
textField
The platform-native text field object. On iOS it’s a UITextField, on OS X it’s a NSTextField.
@property (nonatomic, readonly) UITextField *textField
See Also
Declared In
CCTextField.h
Changing the Text Field's Appearance
backgroundSpriteFrame
The sprite frame used to render the text field’s background.
@property (nonatomic, strong) CCSpriteFrame *backgroundSpriteFrame
See Also
Declared In
CCTextField.h
fontSize
The font size of the text field, defined in the unit specified by the heightUnit component of the contentSizeType.
@property (nonatomic, assign) float fontSize
Declared In
CCTextField.h
padding
Padding from the edge of the text field’s background to the native text field component.
@property (nonatomic, assign) CGFloat padding
Declared In
CCTextField.h
string
The text displayed by the text field. Directly forwarded to/from the native text field object.
@property (nonatomic, strong) NSString *string
Declared In
CCTextField.h