swift - 如何在 tableview 页脚中心的中心显示事件指示器?

标签 swift uiactivityindicatorview

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

my indicator

最佳答案

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

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
  }
}

关于swift - 如何在 tableview 页脚中心的中心显示事件指示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37829234/

相关文章:

swift - [UIActivityIndi​​catorView发布] : message sent to deallocated instance in swift-3

swift - 无效更新: invalid number of rows while using Realm

ios - 多次暂停和恢复 CAEmitterLayer

iphone - UIAlertView 与 UIActivityIndi​​cator 有点矛盾

ios - 另一个(!)事件指示器问题

sqlite - Xcode 在从 SQLite 加载时显示自定义进度指示器

ios - 我如何使用 Split( ) 而不是 componentsSeparatedByString( ) ?

ios - 语义问题 : Cannot find the protocol declaration for ‘ARSessionDelegate’

ios - 如何让pickerView水平滚动?

uiactivityindicatorview - Apple Watch 的 WatchKit 中是否有 ActivityIndi​​cator?