代码之家  ›  专栏  ›  技术社区  ›  user979331

swift 4 UITableView页脚,绝对底部

  •  -1
  • user979331  · 技术社区  · 6 年前

    let customView = UIView(frame: CGRect(x: 0, y: self.view.bounds.height - 50, width: self.view.bounds.width, height: 50))
                customView.backgroundColor = UIColor.red
    
                commentText = UITextField(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width - 50, height: 50))
                commentText.backgroundColor = UIColor.white
                commentText.layer.borderColor = UIColor.gray.cgColor
                commentText.layer.borderWidth = 1
                commentText.borderStyle = .roundedRect
                commentText.placeholder = "Enter Comment"
    
                let submitButton = UIButton(frame: CGRect(x: self.tableView.bounds.width - 50, y: 0, width: 50, height: 50))
                submitButton.setTitle("Go", for: .normal)
                submitButton.backgroundColor = UIColor.blue
                submitButton.addTarget(self, action: #selector(self.submitButtonPressed(_:)), for: .touchUpInside)
    
                customView.addSubview(commentText)
                customView.addSubview(submitButton)
    
                tableView.tableFooterView = customView
    

    以下是截图中的结果:

    enter image description here

    我想做的是把页脚一直放在屏幕的底部,这可能吗?

    3 回复  |  直到 6 年前
        1
  •  2
  •   rmaddy    6 年前

    表视图页脚始终位于表视图的末尾,在表视图的最后一行之后。无论表视图中有多少行,都是这样。

    如果您希望视图保持在屏幕底部,并且无论有多少行都不滚动,那么您不需要表视图页脚。您只需要在屏幕底部添加一个视图。

    最好的解决方案是使用 UIViewController

        2
  •  0
  •   whitekevin    6 年前

    也许您可以只在屏幕视图的底部添加页脚视图,而不将其添加为UITableView的页脚视图,因为您不希望在UITableView滚动时移动textfield和submit按钮。

        3
  •  0
  •   Sin Sopheak    6 年前

    view.addSubView(customView)