Game Development Reference
In-Depth Information
Skinning the UITextField with a UIImage
No, I'm not going to peel off the text field's skin! If you haven't heard the term skin-
ning before, it basically means adding (or changing) a texture to a user interface control
or view. Essentially you change the native look of the control or view and replace it
with your own.
In Listing 15-3 you're adding some more code at the bottom of the addSomeTex-
tFields method in order to create a second UITextField that uses a texture as
background.
Listing 15-3 . Skinning a UITextField View
-(void) addSomeTextFields
{
...
// text field that uses an image as background (aka "skinning")
UITextField* textFieldSkinned = [[UITextField alloc] initWithFrame:←
CGRectMake(40, 60, 200, 24)];
textFieldSkinned.text = @"With background image";
textFieldSkinned.delegate = self;
// load and assign the UIImage as background of the text field
CCFileUtils* fileUtils = [CCFileUtils sharedFileUtils];
NSString* file = [fileUtils fullPathFromRelativePath:@"background-frame.png"];
UIImage* image = [[UIImage alloc] initWithContentsOfFile:file];
textFieldSkinned.background = image;
// get the cocos2d view (it's the CCGLView class which inherits from UIView)
UIView* glView = [CCDirector sharedDirector].view;
// add the text field view to the cocos2d CCGLView
[glView addSubview:textField];
[glView addSubview:textFieldSkinned];
}
 
 
Search Nedrilad ::




Custom Search