【问题标题】:How to add one general button in TableViewController in Swift 3 [closed]如何在 Swift 3 的 TableViewController 中添加一个通用按钮 [关闭]
【发布时间】:2016-12-15 11:44:50
【问题描述】:

我需要向我的TableViewController 添加一个通用或通用按钮,如图所示。如何做到这一点?

【问题讨论】:

  • 此按钮是否需要随表格视图滚动或始终保持可见?

标签: swift uitableview button


【解决方案1】:

你可以试试这个。

let bottomButton = UIButton(frame: CGRect(x: 100, y: 300, width: 100, height: 30))
bottomButton.setTitle("Enter Text Here", for: .normal)
bottomButton.backgroundColor = UIColor.orange
view.addSubview(bottomButton)

您可以根据视图控制器设置 x、y 位置。另外,根据tableViewController的宽高设置宽高。

【讨论】:

  • 不错的解决方案@Priya Arora
【解决方案2】:

如果您想要一个简单的解决方案,您有两种选择:

1.创建一个带有按钮的页脚视图,然后使用以下方法将此页脚添加到您的表格视图中:

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat

此解决方案将使您的按钮随表格视图滚动

2。使用UIViewController 而不是UITableViewController

  • 在情节提要中将 UITableView 添加到您的视图控制器
  • 为 UITableView 创建一个 IBOutlet - 连接它
  • 使您的视图控制器符合UITableViewDelegateUITableViewDataSource
  • 设置tableView.delegate = selftableView.dataSource = self
  • 在情节提要中,在表格视图下方添加一个按钮
  • 为按钮创建 IBOutlet 并连接它

使用此解决方案,您的按钮将始终停留在屏幕上,并且只有表格视图会滚动

【讨论】:

    猜你喜欢
    • 2018-06-05
    • 1970-01-01
    • 2017-06-27
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多