大小类

时间:2017-11-14 12:37:59

标签: ios xcode-storyboard uistackview size-classes

尝试使用iPhone的2个标签和使用尺寸等级的iPad的3个标签来实现UIStackView。

查看层次结构

  1. 默认尺寸类

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

    enter image description here

  2. RxR尺寸等级

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

    enter image description here

  3. 在Storyboard中看起来与预期完全一样,你可以在上面的截图中看到,但在模拟器上iPad视图搞砸了。

    iPhone输出(好的)

    enter image description here

    iPad纵向输出(搞砸了)

    enter image description here

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

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

    我创建了一个sample project

2 个答案:

答案 0 :(得分:2)

似乎您正在使用Interface Builder中的“已安装”复选框隐藏iPhone上的其中一个标签。使用“隐藏”复选框似乎可以解决问题。我猜这是一个错误。

答案 1 :(得分:2)

按照以下步骤来达到您的要求:

  • 将一个水平Stackview拖入界面构建器
  • 设置限制条件:top,leading, =trailing and fixed height
  • 将三个标签拖放到其中并一起选择所有标签并设置一个约束: Equal width
  • 现在选择第二个或中间标签,然后从attribute inspector点击+旁边的installed按钮,并选择常规宽度和高度。它会添加常规的常规变体和uncheck the checkbox for that R,R variation。请参阅下面的屏幕截图以便更好地理解,

enter image description here

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

在我的案例中查看以下iphone and ipad的结果屏幕截图!

iPhone:

enter image description here

iPad:

enter image description here

更新:

如果你想要两个在iPhone中隐藏标签并在iPad中显示,那么为中间标签再添加一个变体:Compact Width Regular Height,取消选中要卸载的复选框。请参阅下面的屏幕截图

enter image description here

相关问题