Skip to content

Instantly share code, notes, and snippets.

@florianbuerger
Created December 12, 2014 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florianbuerger/c08bd42b91b6c231c870 to your computer and use it in GitHub Desktop.
Save florianbuerger/c08bd42b91b6c231c870 to your computer and use it in GitHub Desktop.
Is there a better way to create a UITableView.footerView where you don’t know the height when you create it?
let footer = TableFooterView(frame: CGRectZero)
footer.addButtonWithTitle("Red", backgroundColor: UIColor.redColor(), target: self, action: "redWasPressed:" as Selector)
footer.addButtonWithTitle("Green", backgroundColor: UIColor.greenColor(), target: self, action: "greenWasPressed:" as Selector)
footer.addButtonWithTitle("Blue", backgroundColor: UIColor.blueColor(), target: self, action: "blueWasPressed:" as Selector)
footer.updateConstraintsIfNeeded()
footer.layoutIfNeeded()
footer.frame = CGRectMake(0, 0, footer.intrinsicContentSize().width, footer.intrinsicContentSize().height)
tableView.tableFooterView = footer
@florianbuerger
Copy link
Author

We can’t add constraints to the footerView itself because its size is managed by the UITableView. You can try but the result won’t be what you’d expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment