Siddhesh damble
Siddhesh damble

Reputation: 94

Autolayout UITextfield

I have been trying to achieve following layout in autolayout I want to acheive this

enter image description here

may be i am doing something wrong due to which i am getting following result.I get this

enter image description here

can anyone correct me ?

Upvotes: 1

Views: 84

Answers (3)

Antoine Rucquoy
Antoine Rucquoy

Reputation: 148

As said above, use your element inside a horizontal stackview. Unfortunately, if you’ve a iOS target iOS 9.0, you will have to use another trick. Your stackview will become a normal view which will contain your elements to align. After that, you can the element width to be equal to their superview with the multiplier use.

Per example if you have 3 elements inside your view but you want that the first one being larger than the two others by setting the multiplier with a certain ratio like 2:4 for the first one and 1:4 for the last ones :-)

Upvotes: 0

Rizwan Mehboob
Rizwan Mehboob

Reputation: 1373

This kind of layout is easily accomplished by using UIStackView, Please use UIStackView either in storyboard or in code.

Please check Apple documentation on it https://developer.apple.com/documentation/uikit/uistackview?changes=_6

enter image description here

Upvotes: 2

Manish Mahajan
Manish Mahajan

Reputation: 2092

If you are using storyboard for Textfield then simply give leading and trailing to Textfield. Dont give the fixed width to textfield, it will work for all devices. Same logic if you are setting textfield programatically. Dont give fixed width

Upvotes: 0

Related Questions