iphone - 如何在 iPhone 应用程序中垂直居中显示 UITextField 中的文本

标签 iphone ios uitextfield

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

  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;

关于iphone - 如何在 iPhone 应用程序中垂直居中显示 UITextField 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18566162/

相关文章:

iphone - 在 Objective-c 中,比较 2 个 BOOL 值的安全和好方法?

iphone - 内存泄漏。仪器认为一切都很好

iOS/WebKit : touchmove/touchstart not working on input & textarea

ios - 可选解包失败,当 socket 连接正确时

iphone - UITextField 不会在整个项目中自动大写

iphone - iOS 7 UIDatePicker 高度不一致?

iphone - Google AdMob Ads SDK 仅适用于模拟器

iphone - 如何 - 在 iPhone 上恢复应用程序数据库的位置

ios - 日期选择器在 swift 2.2 中首次单击文本字段时无法打开

ios - UITextField.enabled 为 Yes 或 No 根据 UISwitch.on