Created
June 8, 2016 21:00
-
-
Save pronebird/94d966b4a90fdb1b0b2c68d96d4b2a7c to your computer and use it in GitHub Desktop.
This file contains 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
@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