Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aunnnn/tableheaderviewwithautolayout
Example of how to use AutoLayout with table header view.
https://github.com/aunnnn/tableheaderviewwithautolayout
ios swift swift3 uitableview
Last synced: 3 days ago
JSON representation
Example of how to use AutoLayout with table header view.
- Host: GitHub
- URL: https://github.com/aunnnn/tableheaderviewwithautolayout
- Owner: aunnnn
- Created: 2017-06-06T12:30:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-28T06:29:59.000Z (over 7 years ago)
- Last Synced: 2024-09-24T20:34:29.448Z (3 days ago)
- Topics: ios, swift, swift3, uitableview
- Language: Swift
- Homepage:
- Size: 125 KB
- Stars: 78
- Watchers: 3
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TableHeaderViewWithAutoLayout
Example of how to use AutoLayout with table header view.It comes with UITableView's extension that helps you do this easily.
There are two examples:
1. using UITableView (with header view Xib)
2. using UITableViewController (all in storyboard).Requirements: Xcode 8, Swift 3, iOS 9+ (use anchors)
More detail [here](https://medium.com/@aunnnn/table-header-view-with-autolayout-13de4cfc4343)
![alt gif](http://g.recordit.co/6NIcSgwwSF.gif)
## How to use
1. In viewDidLoad()
```swift
// 1. Setup AutoLayout (do this instead of setting constraints via storyboard)
self.tableView.setTableHeaderView(headerView: self.tableView.tableHeaderView!)// 2. Initial layout update
self.tableView.updateHeaderViewFrame()
```2. (If you want to handle device rotation) In viewWillTransition(to size: with coordinator:)
```swift
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)// 3. Update layout every time device is rotated.
DispatchQueue.main.async {
self.tableView.updateHeaderViewFrame()
}
}
```