我应该如何在 UITableView 下放置一个按钮并让它随着表格的增长而向下移动? [英] How should I place a button under UITableView and have it move down as the table grows?

查看:29
本文介绍了我应该如何在 UITableView 下放置一个按钮并让它随着表格的增长而向下移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求:
我有一张桌子和一个需要放在屏幕上的按钮.该表可以有零到多行.按钮至少需要低于表格内容底部 40 pts,高于屏幕底部 83 pts.所以当只有几行时,按钮离表格的最后一行很远,但是当有很多行时,按钮可能不会出现在屏幕上,直到用户向下滚动表格.

Requirements:
I have a table and a button I need to place on my screen. The table can have zero to many rows. The button needs to be at least 40 pts below the bottom of the table content, and 83 pts above the bottom of the screen. So when there are only a few rows, the button is far away from the last row of the table, but when there are many rows, the button may not appear on the screen until the user scrolls down the table.

我曾考虑使用 UITableView 页脚,但它总是将按钮放在表格内容的最后一行之后.

I have considered using a UITableView footer but it would always place the button right after the last row of the table content.

现在我正在考虑使用 UIScrollView 并将表格和按钮放置在随着表格内容增长而增长的视图中.桌子高度约束也会增加.我会在按钮上使用不等式约束,所以它总是至少低于表格底部 40 pts,高于视图底部 83 pts.

Right now I am considering using a UIScrollView and placing the table and button in a view that grows as the table content grows. The table height constraint would grow as well. I would use inequality constraint on button so it's always at least 40 pts below bottom of table and 83 pts above bottom of the view.

还有更好的方法吗?我描述的好像有点复杂.

Is there a better way though? What I described seems a little complicated.

表格短时的UI设计:

UI design of when the table is short:

当表格很长并从屏幕上滚动时,我没有图片,但按钮在滚动视图的最后一行和底部之间有间距

I do not have a pic for when the table is long and scrolls off the screen, but button has spacing between last row and bottom of scrolled view

推荐答案

另一种解决方案可能是添加带有自定义内容的页脚表格视图.任何 tableview 都有一个页眉和页脚视图,可以根据您的喜好进行设计.

Another solution could be to add a footer table view with your custom content. Any tableview has a header and a footer view and could be designed as you prefer.

在我的情况下(仅作为示例)我设置了 2 个带有标签的 UIViews(颜色只是为了向您展示视图),您可以用按钮替换标签并更改背景颜色.无论是否显示,您都可以动态更改页脚高度,或者隐藏或显示视图,具体取决于您的目的.

In my case (just for example) i set 2 UIViews with a label inside (the color is just to show you the view), you can replace the label with a button and change the background color. To show it or not you can dinamically change the footer height or maybe hide or show the view, depending on your purpose.

希望这有助于:)

这篇关于我应该如何在 UITableView 下放置一个按钮并让它随着表格的增长而向下移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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