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

查看:25
本文介绍了如何将前导填充添加到 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天全站免登陆