在cocos2D iPhone中的UItextfield文本对齐问题 [英] UItextfield text alignment issue in cocos2D iPhone
本文介绍了在cocos2D iPhone中的UItextfield文本对齐问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请查看以下屏幕截图。
这是我的代码,我使用cocos2D
CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159 / 2);
_view = [[CCDirector sharedDirector] openGLView];
//输入用户名
_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:@Arialsize:14]];
_nameField.placeholder = @<输入您的姓名>;
_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];
问题是文本对齐到文本字段的顶部。
我想要它在中间不到顶部。
解决方案
这不应该工作吗?
_nameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
Please take a look of the following screen shot.
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.
解决方案
Shouldn't this work?
_nameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
这篇关于在cocos2D iPhone中的UItextfield文本对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文