How to center UITextField text in Swift

寵の児 提交于 2019-11-30 17:09:45
Dave Wood

You would want to write it like this:

myUITextObject.textAlignment = .center

(Edited to change from .Center to .center)

What you're looking for is the textAlignment property; try this:

myUITextObject.textAlignment = NSTextAlignmentCenter;

Another way to do it, is by using the storyboard.

In fact there is a Vertical and Horizontal Control that you can use for align your element inside the UITextField. In the case above that align the text to the top left:



Hope it helps,

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!