UITextField没有对齐中心

时间:2014-09-20 13:18:27

标签: ios objective-c xcode ipad uitextfield

背景:这是iOS 8,无论是模拟器还是iPad2,Objective-C都不是swift,所有UI都是编码而非故事板。

我希望我的UITextField在编辑之前,期间和之后在中心,垂直和水平方向上对齐。

这就是我正在做的事情:

[textfield setTextAlignment:NSTextAlignmentCenter];
[textfield setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[textfield setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

在编辑期间看起来不错,但之前没有。

在编辑之前,它左对齐:

enter image description here

开始编辑时,它正确居中:

enter image description here

如果新文本比旧文本长,那就是这样:

enter image description here

1 个答案:

答案 0 :(得分:0)

如果有人遇到类似的问题并且想知道我做了什么,我没有解决UITextField的问题,我猜测它是苹果公司的一个错误,所以我切换到UITextView,这很有效。

相关问题