Created
June 18, 2013 09:37
-
-
Save syxc/5804024 to your computer and use it in GitHub Desktop.
How to get the size of a UITableView's content view?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma mark - How to get the size of a UITableView's content view? | |
| #define CGSizesMaxWidth(sz1, sz2) MAX((sz1).width, (sz2).width) | |
| #define CGSizesAddHeights(sz1, sz2) (sz1).height + (sz2).height | |
| + (CGSize)sizeForTableView:(UITableView *)tableView | |
| { | |
| CGSize tableViewSize = CGSizeMake(0, 0); | |
| NSInteger numberOfSections = [tableView numberOfSections]; | |
| for (NSInteger section = 0; section < numberOfSections; section++) { | |
| // Factor in the size of the section header | |
| CGRect rect = [tableView rectForHeaderInSection:section]; | |
| tableViewSize = CGSizeMake(CGSizesMaxWidth(tableViewSize, rect.size), CGSizesAddHeights(tableViewSize, rect.size)); | |
| // Factor in the size of the section | |
| rect = [tableView rectForSection:section]; | |
| tableViewSize = CGSizeMake(CGSizesMaxWidth(tableViewSize, rect.size), CGSizesAddHeights(tableViewSize, rect.size)); | |
| // Factor in the size of the footer | |
| rect = [tableView rectForFooterInSection:section]; | |
| tableViewSize = CGSizeMake(CGSizesMaxWidth(tableViewSize, rect.size), CGSizesAddHeights(tableViewSize, rect.size)); | |
| } | |
| return tableViewSize; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment