ios - 在 UIStackView 控件中调整 UIView 高度

标签 ios swift uistackview

我在 iOS 9 SDK 中使用 UIStackView。 stackview 的高度是 44 点。我在 StackView 中有一个 UILabel 和 UIView,如下所示:

enter image description here

现在,我想让绿色 View 比 44 小很多……很像 20。我该怎么做?

如果没有 UIStackView,我就会打破约束:

[GT.BubbleView:0x14536610]   (Names: '|':UITableViewCellContentView:0x14536fd0 )>",
    "<NSLayoutConstraint:0x146b7300 GT.BubbleView:0x14536610.trailing == UITableViewCellContentView:0x14536fd0.trailingMargin>",
    "<NSLayoutConstraint:0x146c4000 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14536fd0(286)]>")

最佳答案

  1. 首先,您需要在 cell 上添加 UIStackView enter image description here

  2. 需要为您的 UIStackView 添加约束 enter image description here

  3. 调整你的 UIStackView enter image description here

  4. UILabel 拖放到您的 UIStackViewenter image description here

  5. 然后将 UIView 拖放到您的 UIStackViewenter image description here

  6. 添加 green-UIView subview 到 pink UIView enter image description here

  7. 现在您可以向 green-UIView 添加几个约束 enter image description here enter image description here

  8. 现在您可以在模拟器或设备上运行应用程序 enter image description here enter image description here

    请注意,我没有为 UILabel 添加任何约束。

关于ios - 在 UIStackView 控件中调整 UIView 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37403982/

相关文章:

ios - 在具有可移动边缘点的 SWIFT-IOS 中裁剪图像

ios - 如何更改 ipad 的标签位置以填充空间

ios - AutoLayout:在 UIStackView/UITableViewCell 中缩放 UIImageView 时出现问题

ios - 获取 AvCaptureVideoDataOutput availableVideoCVPixelFormatTypes 的实际 NSString

ios - TabBar 在导航到另一个 UIViewController 时不可见

ios - 如何使用可表示协议(protocol)在 SwiftUI 中显示 UICollectionViewController?

ios - 在信标范围内时显示图像而不是颜色

swift - 向 Card 添加一个方法,创建一副完整的纸牌,每个等级和花色的组合各一张

swift - 为带有扩展名的 UIButton 设置字体

swift - 为什么 UIStackView 调整排列 subview 的大小?