简体   繁体   中英

Autolayout UITextfield

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

在此处输入图片说明

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

在此处输入图片说明

can anyone correct me ?

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

在此处输入图片说明

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

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 :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM