我可以使非居中的 UILabel 保持其相对于正在缩放的 UIImageView 的位置吗?
Can I make a non-centered UILabel maintain its position relative to a UIImageView that is being scaled?
我一直在通过结合使用教程、Whosebug 浏览和实验来学习 AutoLayout 的变幻莫测。我在这项工作中的主要目标是学习如何使用 AutoLayout 和最小(最好是 no)代码在 Interface Builder 中定义尽可能多的 UI。
我现在想要实现的是弄清楚如何让 UILabel
(或任何 UIView
子类,真的)保持其相对于 UIImageView
的位置。这是目前在 IB 中如何设置的图片,因此代表了我的意图:Storyboard
我知道如何在 UIImageView
上设置约束,以便根据设备大小调整大小。但我似乎无法弄清楚如何指定告诉 IB 我希望 UILabel
的垂直位置也以相同方式缩放的约束。感觉我本质上是在寻找 UILabel's
垂直位置的纵横比约束。
我试过将 UILabel
和 UIImageView
嵌入另一个 UIView
并在那里设置一些约束。主要感兴趣的是:
UILabel Align center X: Superview
UILabel Top Space to: Superview Equals: 25 (as computed by IB)
不同设备尺寸的结果是:
4 inch iPhone
5.5 inch iPhone
iPad
如您所见,这不是预期的结果!我能做什么?非常感谢您的帮助!
不确定是否可以设置比例间距约束。然而,在我的脑海中,你可以添加一个有约束的透明视图:
top aligned to imageView's top
left aligned to imageView's left
right aligned to imageView's right
bottom aligned to label's top
height proportionally equals to imageView's height
我一直在通过结合使用教程、Whosebug 浏览和实验来学习 AutoLayout 的变幻莫测。我在这项工作中的主要目标是学习如何使用 AutoLayout 和最小(最好是 no)代码在 Interface Builder 中定义尽可能多的 UI。
我现在想要实现的是弄清楚如何让 UILabel
(或任何 UIView
子类,真的)保持其相对于 UIImageView
的位置。这是目前在 IB 中如何设置的图片,因此代表了我的意图:Storyboard
我知道如何在 UIImageView
上设置约束,以便根据设备大小调整大小。但我似乎无法弄清楚如何指定告诉 IB 我希望 UILabel
的垂直位置也以相同方式缩放的约束。感觉我本质上是在寻找 UILabel's
垂直位置的纵横比约束。
我试过将 UILabel
和 UIImageView
嵌入另一个 UIView
并在那里设置一些约束。主要感兴趣的是:
UILabel Align center X: Superview
UILabel Top Space to: Superview Equals: 25 (as computed by IB)
不同设备尺寸的结果是: 4 inch iPhone 5.5 inch iPhone iPad
如您所见,这不是预期的结果!我能做什么?非常感谢您的帮助!
不确定是否可以设置比例间距约束。然而,在我的脑海中,你可以添加一个有约束的透明视图:
top aligned to imageView's top
left aligned to imageView's left
right aligned to imageView's right
bottom aligned to label's top
height proportionally equals to imageView's height