简体   繁体   English

如何让tableview控件适合整个屏幕

[英]How to let the tableview control fit the entire screen

I add a TableView to a new Single View Application.我将 TableView 添加到新的单一视图应用程序。 The exercise requires me to allow the TableView control to fit the entire screen.该练习要求我允许 TableView 控件适合整个屏幕。 But I can't find any function to do this.但我找不到任何 function 来执行此操作。 Should I adjust the parameters in the Table View in Size Inspector?我应该在 Size Inspector 的 Table View 中调整参数吗?

在此处输入图像描述

You really should learn auto-layout and constraints as they're an extremely important part of building up layout in UIKit .你真的应该学习自动布局和约束,因为它们是在UIKit中构建布局的极其重要的部分。
For now, this is how you set your table view (or essentially any view) to fill the screen:现在,这是您设置表格视图(或基本上任何视图)以填充屏幕的方式:

  1. Select your table view Select 你的表格视图
  2. Click on the Add New Constraint button at the bottom right of your storyboard.单击 storyboard 右下方的添加新约束按钮。
  3. Set 0 for top, bottom, left and right.将顶部、底部、左侧和右侧设置为0

That will add 4 constraints that will stretch your table view to fill up all the space available in the screen's safe area.这将添加 4 个约束,这些约束将拉伸您的表格视图以填满屏幕安全区域中的所有可用空间。

例如

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

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