调整UIStackView控件内的UIView高度 [英] Adjusting UIView Height Inside UIStackView Control

查看:2872
本文介绍了调整UIStackView控件内的UIView高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 9 SDK中使用UIStackView。 stackview的高度为44点。我在StackView中有一个UILabel和UIView,如下所示:

I am using a UIStackView in iOS 9 SDK. The height of the stackview is 44 points. I have a UILabel and UIView inside the StackView as shown below:

现在,我想让绿色视图远小于44 ..非常像20.我怎么能这样做?

Now, I want to make the green view much smaller than 44.. much like 20. How can I do that?

更新:没有UIStackView我受到了限制:

UPDATE: Without the UIStackView I am getting breaking constraints:

[GT.BubbleView:0x14536610]   (Names: '|':UITableViewCellContentView:0x14536fd0 )>",
    "<NSLayoutConstraint:0x146b7300 GT.BubbleView:0x14536610.trailing == UITableViewCellContentView:0x14536fd0.trailingMargin>",
    "<NSLayoutConstraint:0x146c4000 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14536fd0(286)]>"

推荐答案

如果你想要达到如下所示的20x20平方:



If you are trying to achieve a 20x20 square like the one below:

然后您需要做的就是添加另一个UIView到您的绿色视图。使UIView的大小为20x20pts。然后将小视图背景更改为绿色和更大的视图的背景圆形清除。

Then all you have to do is add another UIView to your green view. Make that UIView's size 20x20pts. Then change the small view background to green and the larger view's background to clear.

也就是说,此解决方案不需要堆栈视图,可能会使您的UI过于复杂。我建议只使用autolayout。

    $ b $时,Stackviews最有用b
  1. 你想要弥补设备方向的变化,

  2. 希望将很多东西叠加在一起,

  3. 想要创建一个包含许多元素的非常复杂的布局,但是你可以重复
    模式,或者

  4. 只是希望能够删除一个元素或添加一个元素调整自己的大小

  1. you want to compensate for a change in device orientation,
  2. want to stack a lot of things on top of each other,
  3. want to create a very complicated layout with many elements but that has patterns you can repeat, or
  4. simply want to be able to remove an element or add an element in with the sizing correcting itself

该列表并非详尽无遗,但应该让您了解何时以及为何使用堆栈视图。

That list isn't exhaustive, but should give you an idea of when and why you'd use a stack view.

这种行为是微不足道的。您只需在视图上设置约束:
'

This behavior is trivial. You can simply set the constraints on your view: '

然后在stackview上设置约束:

And then set the constraints on the stackview:

希望这会有所帮助,欢呼!

Hope this helps, cheers!

这篇关于调整UIStackView控件内的UIView高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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