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,

<a href="https://i.stack.imgur.com/nmhld.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/nmhld.png" data-original="https://i.stack.imgur.com/nmhld.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

In landscape mode showing like this,

<a href="https://i.stack.imgur.com/H40AG.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/H40AG.png" data-original="https://i.stack.imgur.com/H40AG.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Here is my Constraints Screen

<a href="https://i.stack.imgur.com/h0qZo.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/h0qZo.png" data-original="https://i.stack.imgur.com/h0qZo.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

this my View Controller

<a href="https://i.stack.imgur.com/p9mb0.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/p9mb0.png" data-original="https://i.stack.imgur.com/p9mb0.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>


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


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.


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

<a href="https://i.stack.imgur.com/QnJWv.gif" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/QnJWv.gif" data-original="https://i.stack.imgur.com/QnJWv.gif" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Check Output :-

<a href="https://i.stack.imgur.com/guPkt.gif" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/guPkt.gif" data-original="https://i.stack.imgur.com/guPkt.gif" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

<strong>EDIT :-</strong>

Here i have attached Demo with Scrollview . check it.

<a href="http://s000.tinyupload.com/?file_id=67896183676081291651" rel="nofollow">Constrain with scrollview</a>

Output :-

<a href="https://i.stack.imgur.com/11unL.gif" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/11unL.gif" data-original="https://i.stack.imgur.com/11unL.gif" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>


  • iPhone keyboard pushes page up in phonegap
  • Attach GestureRecogniser to multiple imageviews
  • UIScrollView layoutSubviews behavior changes in iOS 5?
  • PHP: Filter array by date range
  • How to refresh a QFileSystemModel in a QTreeView after files change through another process?
  • MySQL Views: Referencing one calculated field (by name) in another calculated field
  • Value cannot be null.Parameter name: stream error while reading the contents of embeddded file
  • How can I add a gradient that spans two views?
  • psycopg2 and SQL injection security
  • Simulate Holding Ctrl Key
  • Now that Android 4.0 is out, is Multi Touch possible in android emulator?
  • Detecting steady-state by calculating ODE values in ODE function in Matlab
  • how can i do UIView animateWithDuration in viewDidLoad? ios7
  • Can't spy on an event handler even though I can spy on other methods
  • Use SendInput to lock the computer
  • access an alertView's calling view
  • Scala Slick Database Views
  • Change a string in xml into an array in xml easily
  • SVG Fill Width to Child Elements
  • How to set infinite shared access signature policy in azure?
  • Doctrine2 inverse persistance not working in nested forms
  • How to get value from merged-cells in Excel document using OpenXML and C#
  • Java : How to tint this PNG programmatically?
  • redirect_to root_url and return unless @user.activated
  • Can I have a variable number of URI parameters or key-value pairs in Laravel 4?
  • MySQL performance when updating row with FK
  • How to explicitly/implicitly implemented interface members in C++/CLI?
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • uniform generation of points on 3D box
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • Caching attributes in superclass
  • Javascript simulate pressing enter in input box
  • 'TypeError' while using NSGA2 to solve Multi-objective prob. from pyopt-sparse in OpenMDAO
  • bootstrap to use multiple ng-app
  • Cannot Parse HTML Data Using Android / JSOUP
  • python regex in pyparsing
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Getting Messege Twice Using IMvxMessenger
  • Binding checkboxes to object values in AngularJs
  • How to load view controller without button in storyboard?