如何在tableview页脚中心显示活动指示器?

时间:2016-06-15 07:50:02

标签: swift uiactivityindicatorview

我有一个指标视图。我如何在tableview页脚中心显示它。

my indicator

1 个答案:

答案 0 :(得分:2)

例如,您可以像下面这样以编程方式居中:

override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  if section == 0 {
    let footerView = UIView(frame: CGRect.zero)
    footerView.backgroundColor = UIColor.grayColor()

    let activityView = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
    footerView.addSubview(activityView)
    activityView.startAnimating()

    activityView.translatesAutoresizingMaskIntoConstraints = false

    NSLayoutConstraint(
      item: activityView, 
      attribute: .CenterX, 
      relatedBy: .Equal, 
      toItem: footerView, 
      attribute: .CenterX, 
      multiplier: 1.0, 
      constant: 0.0
    ).active = true

    NSLayoutConstraint(
      item: activityView, 
      attribute: .CenterY, 
      relatedBy: .Equal, 
      toItem: footerView, 
      attribute: .CenterY, 
      multiplier: 1.0, 
      constant: 0.0
    ).active = true

    return footerView
  } else {
    return nil
  }
}