How to fixed text field position in all iphone device?

时光怂恿深爱的人放手 提交于 2019-12-11 02:52:39

问题


I am need set UITextField position fixed in all device screen.

I want to set UITextField position fixed.

Please Help me.

Thanks.


回答1:


Read this. It will help :

Or refer to any auto layout tutorial. There are plenty online.




回答2:


there are three types layout using in iOS

  1. autolayout

    Tutorial1,Tutorial2.

if you are not interested in autolayout , go to second option

  1. autosizing

    Tutorial1,Tutorial2.

    1. autoresizingMask - here you can set height,width, x and Y coordinates programmatically

    Tutorial1,Tutorial2




回答3:


you need to use autolayout to solve your problem.




回答4:


You have to insert a UITextField into your UIViewController inside the UIStoryboard. Then you need to set the constraints by right clicking from the UITextField to the positions you want to fix it to.

Use following constraints:

  • Top Space to Container
  • Center Horizontally in Container
  • Leading Space to Container
  • Trailing Space to Container

Here is an example how I did it:

Like you can see in the screenshot, there are also constraints to the UILabel called Title, Center X and Vertical Spacing. If you have other elements above, you have to position the UITextField relative to these elements.

And always think about:

Insert all elements you want inside your view, then start to fix them with constraints, starting from the first at the top and going down till you prepared all UIControls in your UIView. And use the preview view inside the Assistent Editor ( Alt + cmd + Enter ), and select at the top Preview:

Here you can insert phones you want and every change on constraints inside the UIStoryboard will be displayed here immediately, so you don't have to run your app every time again just to see, something again didn't work:



来源:https://stackoverflow.com/questions/31980223/how-to-fixed-text-field-position-in-all-iphone-device

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