2014-09-20 94 views
0

背景:这是iOS 8,模拟器和iPad2,Objective-C都不快捷,所有的UI都是编码而不是故事板。UITextField未对齐中心

我希望我的UITextField在编辑之前,编辑过程中和编辑之后在中心对齐,垂直和水平对齐。

这是我在做什么:

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

它看起来编辑时好,而不是之前。

编辑之前,它的左对齐:

enter image description here

当开始编辑它的正确中心:

enter image description here

而且,如果新的文本比旧文本越长,它像这个:

enter image description here

回答

0

如果任何人有类似的问题,并想知道我做了什么,我没有与UITextField的问题的解决方案,我猜这是苹果的一端的错误,所以我切换到UITextView,作品。