UIStackView with UILabels in Xcode 7.3

女生的网名这么多〃 提交于 2019-11-29 06:37:42

This is a bug appears in Xcode 7.3, so you can ignore it as what he said matt.

The problem

The storyboard can not calculate the intrinsic content size of subviews when you use UIStackView

Solution

If you hate seeing warnings in your storyboard you can fixe it like below :

You should do these steps for each subview of your UIStackView

  • Tap the warning of your subview
  • Tap "Update frames" option
  • Choose "Placeholder" of the subview intrinsic size in the fourth menu in the inspector view

Like that you will not see warnings, and you can see if any ambiguities exist

The disadvantage is you should do this steps each time you change your subview (example: changing the size of text of an UILabel)

Hoping that Apple fixes this bug in the next release

Ignore the warnings. The storyboard has never quite understood stack views. The constraints will be correct at runtime and that's all that matters.

I have a different trick for eliminating the warnings and making 'update frames' work properly.

Advantage:

Doesn't require changing placeholder values every time text changes

Disadvantage:

Extra views that are unnecessary when Xcode 8 comes out

Steps:

  • Embed each UILabel inside a UIView.
  • Constrain the UIView to size itself based on the label (match leading, trailing, bottom, and top)

It seems like UIStackView (in Xcode 7) can't understand the intrinsic content size of a label, but CAN understand the intrinsic content size of a view - so put the label in a view and presto!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!