简体   繁体   English

如何在设置了“等宽”的scrollview中嵌入的stackview中,将标签文本设置为远离视图边缘?

[英]How to set label text away from edge of view in a stackview embedded in scrollview where 'equal widths' is set?

After a frustrating few hours trying to get a stackview of labels containing text to be constrained to the vertical edges of the screen while allowing scrolling up and down I managed it. 令人沮丧的几个小时后,试图获取包含文本的标签的堆栈视图,这些文本被限制在屏幕的垂直边缘,同时允许上下滚动,我对此进行了管理。 However I want the text to be set away from the edge of the screen - it looks awkward the way it is. 但是,我希望文本远离屏幕边缘放置-看起来很尴尬。 The problem is that I currently have an 'equal widths' constraint set so that the stackview is constrained to avoid horizontal scrolling. 问题是我目前设置了一个“等宽”约束,因此应限制stackview以避免水平滚动。 When I add further constraints to the view it conflicts. 当我向视图添加更多约束时,就会发生冲突。

This is what it looks like on screen: 这是屏幕上的样子:

在屏幕上查看

And this is what the set up in interface builder looks like: 这是在界面构建器中设置的样子: 界面构建器视图

What is the most straightforward way to squeeze that text in slightly away from the screen edges? 将文本稍微远离屏幕边缘的最直接方法是什么? I can space the labels from each other easily enough using the Spacing option of the stackview but can't find an easy solution to space it from the vertical edges without removing the 'equal widths' constraint which messes the whole thing up:/ 我可以使用stackview的Spacing选项将标签彼此轻松地隔开,但是找不到一种简单的解决方案,可以在不删除“等宽”约束的情况下将其与垂直边缘隔开,这会弄乱整个事情:/

To set a proportional value (versus an equal value) click on the Edit option next to constraint titled Equal Width to: 要设置比例值(相对于相等值),请单击标题为“ 等宽”的约束旁边的“ 编辑”选项, 以:

在此处输入图片说明

This will cause a little popup to appear. 这将导致出现一些弹出窗口。 Under multiplier you can set a proportional width. 在乘数下,您可以设置比例宽度。 For instance, if you want something to take up 50% of the screen you would set multiplier=0.5. 例如,如果您希望某物占据屏幕的50%,则可以将multiplier = 0.5设置为。

Note: Here it's already called Proportional Width, the title will change when you set the multiplier. 注意:此处已经称为“比例宽度”,设置乘数时标题将更改。

Embed your stackview in another view with your desired top, leading, bottom and trailing constraints. 将堆栈视图嵌入到具有所需顶部,顶部,底部和尾部约束的另一个视图中。 For the view in which you embed the stackview set top, leading, bottom, trailing constraints to scrollview with value 0, plus set equal width with your main view. 对于您在其中嵌入stackview的视图,将top,lead,bottom,trailing约束设置为滚动值为0的滚动视图,并设置与主视图相等的宽度。 For scrollview top, leading, bottom and trailing constraints of 0 to main view. 对于滚动视图,主视图的上,前,下和尾约束为0。 In that way your embedding view will determine the width for scrollview, and provide leading and trailing for the stack view. 这样,您的嵌入视图将确定滚动视图的宽度,并为堆栈视图提供前导和尾随。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM