简体   繁体   中英

How can I use autolayout to program a subview to take up 50% of its superview's width but remain a constant height?

As I said, I have two subviews that I want to fit their superview, 50% width each. But I don't want their heights to change. I know how to use apsect ratio for changing height and width - how can I adapt this for only width?

I believe this answers your question :)

Sometimes I find it easy to create two views, side by side - each 50% width, and just set them to have equal widths. Align the left view on the left to the superview and the right view on the right to the superview. Also add the height constraint to set the specific height.

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