Nic*_*ard 2 interface-builder uiview ios autolayout
UIView
我的布局中有一个固定在我的VC侧面.在其中我有一个图标UIImageView
,UILabel
旁边就是那个.UIView
无论标签内部的文本有多长,我都希望这两者在中心对齐.(类似于如何使用text-align:center;在CSS中对齐图像和文本中心).
| UIView |
| |
| |
| |
| |image| |label| |
| |
| |
| |
| |
Run Code Online (Sandbox Code Playgroud)
有时标签可能很长,但我仍然需要它们居中:
| UIView |
| |
| |
| |
| |img| |label is long| |
| |
| |
| |
| |
Run Code Online (Sandbox Code Playgroud)
我知道怎么用,Autolayout
但这个让我感到难过,因为我无法创造一个"持有者" UIView
并将其作为中心.我需要一些帮助来确定在IB中添加的约束.
想法?
基于@Mahmoud Adam的回答,我们可以在故事板中完全做到这一点.
UIView
相对于其超视图.UIImage
,UILabel
以便它们固定到的边缘UIView
.该UIView
会成长为UIImage
与UILabel
成长这里面.