Swift:UITableViewController - 修改 UITableView 和 View Controller 之间的边距 [英] Swift: UITableViewController - modify margin between UITableView and View Controller

查看:31
本文介绍了Swift:UITableViewController - 修改 UITableView 和 View Controller 之间的边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用 UITableViewController.它运行良好,但默认的 UITableViewController 在嵌入其中的 UITableView 和 UITableViewController 的主视图之间增加了一些间距.看下图.如何从故事板或代码中删除/修改此间距表单?

I am using UITableViewController in my app. It works well but default UITableViewController is adding some spacing between UITableView embedded inside it and main View of UITableViewController. Look at below image. How can I remove/modify this spacing form storyboard or from code?

蓝色是我的自定义行.间距在此蓝色 tableView 行和绿色导航栏之间.

In blue is my custom row. The spacing is between this blue tableView row and green navigation bar.

推荐答案

在 ViewDidLoad 中添加这个对我有帮助:

Adding this in ViewDidLoad helped me:

tableView.tableHeaderView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 0.0, height: CGFloat.leastNormalMagnitude))

也可以通过实现委托方法来删除它

It is also possible to remove this by implementing delegate methods

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {

      return CGFloat.leastNormalMagnitude
}

但在第二种方法中,它也会自动删除 TableView 部分之间的所有间距.

But in the second approach it automatically removes all spacing also between TableView sections.

我也听说 UITableView 的 Grouped 样式会出现此问题.

I have also heard that this problems occurs for Grouped style of UITableView.

这篇关于Swift:UITableViewController - 修改 UITableView 和 View Controller 之间的边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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