如何添加前导填充以添加到UIStackView中添加的视图 [英] How to add leading padding to view added inside an UIStackView

查看:188
本文介绍了如何添加前导填充以添加到UIStackView中添加的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的设置:我有一个UIScrollView,其前缘,顶部,试验边缘均设置为0.在其中,我添加了一个具有以下约束的UIStackView:

This is my setup: I have an UIScrollView with leading,top, trialing edge set to 0. Inside this I add an UIStackView with this constraints:

stackView.centerYAnchor.constraintEqualToAnchor(selectedContactsScrollView.centerYAnchor).active = true  
stackView.leadingAnchor.constraintEqualToAnchor(selectedContactsScrollView.leadingAnchor).active = true

在堆栈视图中,我添加了一些视图.
我的问题是,由于种种限制,添加到堆栈视图的第一个视图也将具有前导边缘=0.

Inside the stack view I add some views.
My issue is that because of the constraints the first view added to stack view will also have leading edge = 0.

我可以在第一个视图中添加一些填充的方式是什么?无需调整滚动视图约束.

What are the ways that I could add some padding to the first view ? Without adjusting the scroll view constraints.

推荐答案

您提供的解决方案并未在UIStackView中添加视图填充(如您在问题中所希望的那样),但为该视图添加了前导UIStackView.

The solution you have provided doesn't add a padding for your views inside your UIStackView (as you wanted in the question), but it adds a leading for the UIStackView.

一个解决方案可能是在原始UIStackView中添加另一个UIStackView并引导到新的UIStackVIew.然后,将您的视图添加到这个新的UIStackView中.

A solution could be to add another UIStackView inside your original UIStackView and give the leading to this new UIStackVIew. Then, add your views to this new UIStackView.

提示,您可以使用Interface Builder完全完成此操作.换句话说,无需为此编写代码.

Hint, you can do that completely using Interface Builder. In other words, no need to write code for it.

这篇关于如何添加前导填充以添加到UIStackView中添加的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆