Ios 在UITableview的页脚底部添加一个按钮

Ios 在UITableview的页脚底部添加一个按钮,ios,swift,uitableview,Ios,Swift,Uitableview,我正试图在页脚的底部中央制作甜甜圈,但它没有发生!!这就是我现在看到的 您应该做的是,在创建按钮后,通过告诉所需的原点来确定它可能是什么(请注意,它是Swift 4): 因此,如果您无法使用Swift,请补充: func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { guard section == 0 else { return nil } l

我正试图在页脚的底部中央制作
甜甜圈,但它没有发生!!这就是我现在看到的


您应该做的是,在创建按钮后,通过告诉所需的原点来确定它可能是什么(请注意,它是Swift 4):

因此,如果您无法使用Swift,请补充:

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

    guard section == 0 else { return nil }

    let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 44.0))
    let doneButton = UIButton(frame: CGRect(x: 0, y: 0, width: 130, height: 44.0))
    // here is what you should add:
    doneButton.center = footerView.center

    doneButton.setTitle("become a captian?", for: .normal)
    doneButton.backgroundColor = .lightGray
    doneButton.layer.cornerRadius = 10.0
    doneButton.shadow = true
    doneButton.addTarget(self, action: #selector(hello(sender:)), for: .touchUpInside)
    footerView.addSubview(doneButton)

    return footerView
}

在声明按钮之后。通过将按钮设置为与容器视图(FooTeVIEW)中心相同,它应该正好位于它的中间(X和Y轴),这样你就可以得到你想要的外观。

你应该做的是在创建按钮之后确定它,告诉它所需的原点,它可能是(请注意,它是Swift 4):

doneButton.center = footerView.center
因此,如果您无法使用Swift,请补充:

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

    guard section == 0 else { return nil }

    let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 44.0))
    let doneButton = UIButton(frame: CGRect(x: 0, y: 0, width: 130, height: 44.0))
    // here is what you should add:
    doneButton.center = footerView.center

    doneButton.setTitle("become a captian?", for: .normal)
    doneButton.backgroundColor = .lightGray
    doneButton.layer.cornerRadius = 10.0
    doneButton.shadow = true
    doneButton.addTarget(self, action: #selector(hello(sender:)), for: .touchUpInside)
    footerView.addSubview(doneButton)

    return footerView
}
在声明按钮之后,通过将按钮设置为与容器视图(FooTeVIEW)中心相同,它应该正好位于它(X和Y轴)的中间,这样你就可以得到你想要的外观。
doneButton.center = footerView.center


添加容器视图并在容器视图中居中放置按钮。数学应该相当简单。添加容器视图并在容器视图中居中放置按钮。数学应该相当简单。谢谢。这有助于将按钮居中放置,但按钮不在UITablevew的底部。如何操作?@leo0019尝试添加将背景色添加到
footerView
并查看添加的位置。谢谢。这有助于将按钮居中,但按钮不在UITableView的底部。如何执行此操作?@leo0019尝试将背景色添加到
footerView
并查看添加的位置。