User558
User558

Reputation: 1175

How to set Horizontal text field in landscape mode with auto layout?

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,

enter image description here

In landscape mode showing like this,

enter image description here

Here is my Constraints Screen

enter image description here

this my View Controller

enter image description here

Upvotes: 0

Views: 700

Answers (3)

Badal Shah
Badal Shah

Reputation: 7612

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

enter image description here

Check Output :-

enter image description here

EDIT :-

Here i have attached Demo with Scrollview . check it.

Constrain with scrollview

Output :-

enter image description here

Upvotes: 0

Mahendra
Mahendra

Reputation: 8924

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.

Upvotes: 1

theDC
theDC

Reputation: 6484

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

Upvotes: 1

Related Questions