[英]Auto Layout for complex view in Table View Cell
I know this might not be the best question but I really need to a starting point: 我知道这可能不是最好的问题,但我确实需要一个起点:
If I wanted to create a layout as the one below (using auto layout): 如果要创建以下布局(使用自动布局):
What I tried was: 我试过的是:
Bottom Space: 140, Top space 10, Leading Space 20, Trailing space 20
. Bottom Space: 140, Top space 10, Leading Space 20, Trailing space 20
。 (I didn't touch the stack views inside this final stack view. I only put layouts on the main horizontal stack view created in this step). After 4bar suggestions: 经过4bar建议:
Please note I have not touched the first name, facebook.com, or bio label at the bottom. 请注意,我没有触摸底部的名字,facebook.com或生物标签。
If you have not set the distribution mode for your outermost horizontal stack view, it will default to UIStackViewDistributionFill, in which case the arranged subviews will stretch to fill the whole width according to their hugging priority. 如果您尚未为最外面的水平堆栈视图设置分布模式,它将默认为UIStackViewDistributionFill,在这种情况下,已排列的子视图将根据其拥抱优先级拉伸以填充整个宽度。 Increase the content hugging priority on the image view (say, to 251) to prevent it from stretching.
增加图像视图上具有优先级的内容(例如,增加到251)以防止其拉伸。 Also, if the image size is larger than the space you'd like to devote to it, you may also need to set additional width or height constraints on the image to override its intrinsic size.
另外,如果图像尺寸大于您要占用的空间,则可能还需要在图像上设置其他宽度或高度约束,以覆盖其固有尺寸。
The main thing to understand is that UIStackView's size is driven by the intrinsic sizes of its arranged subviews, plus spacing. 要了解的主要内容是,UIStackView的大小由其排列的子视图的固有大小加上间距驱动。 In Fill mode, if too much space is available, content hugging priorities are used to determine which view to stretch;
在“填充”模式下,如果可用空间过多,则使用内容包含优先级来确定要拉伸的视图; if too little space is available, compression resistance priorities are used to determine which view to compress.
如果可用空间太小,则使用抗压缩优先级来确定要压缩的视图。
If you want the image to look like a square, you have to pin the width and height of the image to the same value. 如果要使图像看起来像正方形,则必须将图像的宽度和高度固定为相同的值。 Then set Mode to AspectFit so that image won't look stretched.
然后将“模式”设置为AspectFit,以使图像看起来不会拉伸。 Pin the width of the labels like 'posts'.
固定标签的宽度,例如“帖子”。 So that they will show the entire text.
这样他们将显示整个文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.