OGeek|极客世界-中国程序员成长平台

标题: ios - 具有大小类的 UIStackView subview [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:52
标题: ios - 具有大小类的 UIStackView subview

尝试使用 size classes 来实现 UIStackView,其中 iPhone 有 2 个标签,iPad 有 3 个标签。

查看层次结构

  1. 默认尺寸等级

    [UIStackView] 
      [UILabel 1] [UILabel2]
    [UIStackView] 
    

    enter image description here

  2. RxR 尺寸等级

    [UIStackView] 
      [UILabel 1] [UILabel2] [UILabel3]
    [UIStackView] 
    

    enter image description here

正如您在上面的屏幕截图中看到的那样,它在 Storyboard 中看起来完全符合预期,但在模拟器 iPad 上的 View 却一团糟。

iPhone 输出(好的)

enter image description here

iPad 纵向输出(搞砸了)

enter image description here

iPad 横向输出(搞砸了) enter image description here

iPad 发生了什么?这是一个错误还是我错过了什么? 谢谢。

我创建了一个 sample project .



Best Answer-推荐答案


按照以下步骤实现您的要求:

enter image description here

你就完成了!现在您的中心标签将不会显示在 iPad 中,而每个标签都将显示在 iPhone 中!

在我的例子中,请看下面 iphone 和 ipad 的结果截图!

iPhone:

enter image description here

iPad:

enter image description here

更新:

如果您想要两个在 iPhone 中隐藏标签并在 iPad 中显示,则再添加一个变体:Compact Width Regular Height 用于中间标签并取消选中复选框以卸载。引用下面的截图,

enter image description here

关于ios - 具有大小类的 UIStackView subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47286134/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4