更改tableviewcell内部元素上的位置

发布于 2025-01-19 22:19:58 字数 386 浏览 1 评论 0原文

所以我在 xib 单元格内有一个视图,在该视图内有 2 个元素,一个位于视图中间的标签和一个带有隐藏文本的按钮。 当此按钮从 isHidden 变为 isNot 时,我希望标签距视图顶部 20 px,按钮距视图底部 20 px。

有人可以和我一起经历这个,就像你向一个完全的初学者解释的那样吗?我对快速编程还不太了解,这是我第一次尝试做这样的事情。

我会在图片中给你一个我也想得到的例子。

按钮隐藏

按钮不隐藏

So I have a view inside an xib cell, inside this view I have 2 elements, one label that is in the middle of the view and a button with text that is hidden.
When this button goes from isHidden to isNot I want the label to be 20 px from the top of the view and the button 20px from the bottom of the view.

Could anyone go through this with me like u explained it to a complete beginner? I'm not that far into swift programming, and this is the first time I'm trying to do something like this.

I will give you an example in pictures what I'm trying to get as well.

buttonisHidden

buttonisNotHidden

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2025-01-26 22:19:58

我建议将垂直堆栈视图作为包含视图。设置一个自动划分约束,以将堆栈视图置于单元格中。

当您显示/隐藏其内部的视图时,堆栈视图足够聪明,可以调整其尺寸和布局。 (将视图隐藏在堆栈视图中的效果与删除它相同,而没有掩盖子的视图与添加它的效果相同。)

如果您正确设置了所有内容,则应只能显示/隐藏您的按钮布局应该只能工作

I suggest using a vertical stack view as your containing view. Set up an AutoLayout constraint to center your stack view in your cell.

A stack view is smart enough to adjust its size and layout when you show/hide the views inside it. (hiding a view in a stack view has the same effect as removing it, and un-hiding a child view has the same effect as adding it.)

If you set up everything correctly, you should be able to just show/hide your button and the layout should just work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文