简体   繁体   中英

UIStackView inside UITableViewCell is not acting as expected

I placed a UIStackView inside a UITableViewCell with 3 subviews and selected it to fill equally.

As it looks good on the iPhone 7 preview, the auto layout constraints seem to be broken for the smaller screens. The width of the stack view is greater than the screen width.

在此处输入图片说明

在此处输入图片说明

What am I missing?

Try running stackview.layoutIfNeeded() on each cell's stack view in your cellForRowAt method. Also are you adding any constraints to the views you are adding to the stack view? if you are doing it via code you could say newView.widthAnchor.constraint(equalToConstant: (UIScreen.main.bounds.width / 3)).isActive = true to ensure that its the right size (assuming you didn't want any space between them).

your issue is clearly not in uistackview constraints, it's in the table it self.

please add a leading and trailing constraints for the table view and it will work fine.

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