user976007
user976007

Reputation: 35

Swift TextField has no width

I have just started learning swift and have been trying to create a layout using the scoreboard.

I have placed two textfields and set the constraints properly using the document outline. However when I run the emulator the Text Fields display wrong.

I have attached a screenshot, The left is what happens in my emulator the right is what I see in the view editor in xCode Screenshot

Upvotes: 2

Views: 2866

Answers (2)

Bhavin Bhadani
Bhavin Bhadani

Reputation: 22374

You used the wrong constraints.....as you give x and y position to edges of the screen you can not maintain the width of the textview...

ok here is some images ...just follow it...

enter image description here

enter image description here

In first image i just give x and y position with height and width to first textfield and in the second one i give equal width and heigh to first one.

Upvotes: 3

Schemetrical
Schemetrical

Reputation: 5536

You used the wrong constraints. You set it so its constant inset from the two sides. If the screen gets small, the constant inset stays the same and it squeezes the textField.

You want to keep a constant width of the textField so no matter what size the screen is, it will keep the constant width.

Upvotes: 0

Related Questions