SST
SST

Reputation: 2040

UItextfield text alignment issue in cocos2D iPhone

Please take a look of the following screen shot.

alt text http://img442.imageshack.us/img442/8027/img0402k.png

Here is my code, I am using cocos2D

CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);  
_view = [[CCDirector sharedDirector]openGLView];

 // Input the user name
_nameField = [[UITextField alloc]initWithFrame:CGRectMake(130.0, 270.0, 200.0, 30.0)];
_nameField.transform = transform;
_nameField.adjustsFontSizeToFitWidth = YES;
_nameField.textColor = [UIColor blackColor];
[_nameField setFont:[UIFont fontWithName:@"Arial" size:14]];
_nameField.placeholder = @"<Enter Your Name>";
_nameField.backgroundColor = [UIColor clearColor];
_nameField.autocorrectionType = UITextAutocorrectionTypeNo;
_nameField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
_nameField.textAlignment = UITextAlignmentCenter;
_nameField.keyboardType = UIKeyboardTypeDefault;
_nameField.returnKeyType = UIReturnKeyDone;
_nameField.tag = 0;
_nameField.delegate = self;
_nameField.clearButtonMode = UITextFieldViewModeNever;
_nameField.borderStyle = UITextBorderStyleRoundedRect;

[_view addSubview:_nameField];

The problem is the text is aligned to the top of the text field. I want it to be in the middle not to top. There is too much space in the bottom.

please suggest me the way.

Upvotes: 2

Views: 4078

Answers (1)

Jeff B
Jeff B

Reputation: 30099

Shouldn't this work?

_nameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

Upvotes: 11

Related Questions