Skip to content

Instantly share code, notes, and snippets.

@pronebird
Created June 8, 2016 21:00
Show Gist options
  • Save pronebird/94d966b4a90fdb1b0b2c68d96d4b2a7c to your computer and use it in GitHub Desktop.
Save pronebird/94d966b4a90fdb1b0b2c68d96d4b2a7c to your computer and use it in GitHub Desktop.
@interface UITableViewDynamicTypeConstantsDelegate : NSObject<UITableViewDataSource>
@end
@implementation UITableViewDynamicTypeConstantsDelegate
- (NSInteger)tableView:(__unused UITableView *)tableView numberOfRowsInSection:(__unused NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
}
@end
@implementation UITableView (DynamicTypeConstants)
+ (UIEdgeInsets)defaultCellLayoutMargins {
static UITableView *tableView;
static id tableViewDelegate;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
tableViewDelegate = [[UITableViewDynamicTypeConstantsDelegate alloc] init];
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) style:UITableViewStylePlain];
tableView.rowHeight = UITableViewAutomaticDimension;
tableView.estimatedRowHeight = 44;
tableView.dataSource = tableViewDelegate;
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
});
[tableView reloadData];
UITableViewCell *cell = [[tableView visibleCells] firstObject];
return cell.layoutMargins;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment