Amrmsmb
Amrmsmb

Reputation: 11416

How to force TextField to be fully stretched horizontally in Landscape mode

I a beginner in iOS programming.

I was following a tutorial, and I had to create TextField as shown in the picture below. what I am trying to do is, to force the width of the TextField to expand when the screen in in Landscape mode. In the tutorial I am following, this step is explained and according to the that tutorial I have to press ctrl and drag the TextField vertically to invoke the AutoLayout engine, I did that but when I rotate the simulator the width doesn't grow.

image vertically:

enter image description here

image horizontally

enter image description here

Upvotes: 1

Views: 359

Answers (2)

janusfidel
janusfidel

Reputation: 8106

Set the Leading and Trailing space of your UITextField to your view. See screenshot below:

enter image description here

You also need to set the vertical constraints (Top/Bottom/Height) otherwise you will receive an error. From my example I set the Top spacing and Height since UITextField usually have constant heights.

Upvotes: 1

André Slotta
André Slotta

Reputation: 14040

for the horizontal layout you have to...

  1. ctrl drag from the textfield to the left of it and add a leading constraint to its superview
  2. ctrl drag from the textfield to the right of it and add a trailing constraint to its superview

and - if you didn't already do that - you also have to ctrl drag from the textfield to the top of it and add a top constraint (to the top layout guide for example) to set its vertical position

Upvotes: 1

Related Questions