How to set Horizontal text field in landscape mode

2019-09-19 00:54发布

问题:

In my app i want to set text field width according screen size in landscape mode,using auto layout.it's working portrait perfectly in land scape mode not working.

Here is my Screen with auto layout,

In landscape mode showing like this,

Here is my Constraints Screen

this my View Controller

回答1:

I suppose you must have some superview under this layout that has explicit width set.

How does it look like when you tweak simulated metrics like size and orientation in your storyboard? Alse remember to double check the view hierarchy.

Check the size inspector, your contraints should be: trailing space to superview, leading space to superview, and some top and bottom space. And don't set explicit width value

EDIT: As you can see, the view which is the superview for your textfields and actually whole layout, has the explicitly set width value. Delete this value and instead set both trailing and leading space. This would work



回答2:

Constraints for scrollview - leading, trailing, top and bottom and equal width to superview.

Constraints for view inside scrollview - leading, trailing, top and bottom to scrollview and equal width to scrollview.

And the constraints given to textfields, buttons, etc. are correct. You just need to revise scrollview's and view's(inside scrollview) constraints.



回答3:

Don't need to set Centre constrain. Just set top , Leading and Trialing . so, Autolayout Adjust size automatically. check below image ,

Check Output :-

EDIT :-

Here i have attached Demo with Scrollview . check it.

Constrain with scrollview

Output :-