[UIView不会改变设备尺寸时的宽度

问题描述 投票:0回答:1

我的情节提要中有一个UIView。前导和尾随为16,元素的宽度不固定。

enter image description here

我将UILabel附加到此UIView(-容器),当新的和现有的UILabel超过容器的宽度时,它将移至下一个“行”。 “ containerWidth”(UIView.frame.size.width)是382。

**// If current X + label width will be greater than container view width
// .. move to next row**
if (currentOriginX + labelHashtag.frame.width > containerWidth) {
      currentOriginX = 0
      currentOriginY += tagHeight + tagSpacingY
      }

它对于iPhone XSM正常工作:

enter image description here

但是当我在iPhone 8上运行代码时,容器的宽度仍然为382,UILabel出现在屏幕之外:

enter image description here

为什么我的UIView大小总是相同?为什么根据设备使用约束时没有自动调整大小?

swift xcode uiview constraints
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.