我有一个iPhone应用程序,其中有textfield,它工作正常,但问题是它从文本字段顶部显示文本,我希望它位于居中对齐的verticaly。这是我的文本字段代码。

  herdTextFieldSecond=[[UITextField alloc] initWithFrame:CGRectMake(108,1052,259,36)];
herdTextFieldSecond.textAlignment =  UITextAlignmentLeft;



herdTextFieldSecond.textColor = [UIColor blackColor];
    herdTextFieldSecond.borderStyle =UITextBorderStyleRoundedRect;
herdTextFieldSecond.text=@"";
herdTextFieldSecond.font = [UIFont fontWithName:@"Helvetica" size:16];
herdTextFieldSecond.delegate=self;
herdTextFieldSecond.layer.borderWidth =1;
    herdTextFieldSecond.layer.borderColor = [UIColor darkGrayColor].CGColor;
    herdTextFieldSecond.layer.cornerRadius=5;

最佳答案

使用以下代码在UITextFiled中垂直对齐文本:

MyTextFieldName.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

10-08 08:06