Skip to content

Instantly share code, notes, and snippets.

@christ776
Created August 4, 2016 14:56
Show Gist options
  • Save christ776/1e30b3d0b3b8aa423f475ff483260bee to your computer and use it in GitHub Desktop.
Save christ776/1e30b3d0b3b8aa423f475ff483260bee to your computer and use it in GitHub Desktop.
protocol TableViewFooter:class {
var footerActivityIndicator:UIActivityIndicatorView! {get set}
var tableView:UITableView! {get set}
func setupTableViewFooter()
}
extension TableViewFooter {
func setupTableViewFooter() {
let footerView = UIView(frame:CGRectMake(0, 0, 0, 44))
// set up activity indicator
footerActivityIndicator = UIActivityIndicatorView(frame:CGRectMake(0, 0, 44, 44))
footerActivityIndicator.translatesAutoresizingMaskIntoConstraints = false
footerActivityIndicator.hidesWhenStopped = true
footerActivityIndicator.activityIndicatorViewStyle = .Gray
footerView.addSubview(footerActivityIndicator)
// Center Vertically
let centerYConstraint = NSLayoutConstraint(item:self.footerActivityIndicator,attribute:.CenterY,relatedBy:.Equal,
toItem:footerView,attribute:.CenterY,multiplier:1.0,constant:0.0)
footerView.addConstraint(centerYConstraint)
// Center Horizontally
let centerXConstraint = NSLayoutConstraint(item:self.footerActivityIndicator,attribute:.CenterX,relatedBy:.Equal,
toItem:footerView, attribute:.CenterX,multiplier:1.0,constant:0.0)
footerView.addConstraint(centerXConstraint)
tableView.tableFooterView = footerView
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment