Skip to content

Commit c624e4d

Browse files
Merge pull request forkingdog#358 from forkingdog/1.7-Dev
accessory and index title width problem
2 parents 912b3ce + c1435eb commit c624e4d

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

Classes/UITableView+FDTemplateLayoutCell.m

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ - (CGFloat)fd_systemFittingHeightForConfiguratedCell:(UITableViewCell *)cell {
3232
cellBounds.size.width = contentViewWidth;
3333
cell.bounds = cellBounds;
3434

35-
CGFloat accessroyWidth = 0;
35+
CGFloat rightSystemViewsWidth = 0.0;
36+
for (UIView *view in self.subviews) {
37+
if ([view isKindOfClass:NSClassFromString(@"UITableViewIndex")]) {
38+
rightSystemViewsWidth = CGRectGetWidth(view.frame);
39+
break;
40+
}
41+
}
42+
3643
// If a cell has accessory view or system accessory type, its content view's width is smaller
3744
// than cell's by some fixed values.
3845
if (cell.accessoryView) {
39-
accessroyWidth = 16 + CGRectGetWidth(cell.accessoryView.frame);
46+
rightSystemViewsWidth += 16 + CGRectGetWidth(cell.accessoryView.frame);
4047
} else {
4148
static const CGFloat systemAccessoryWidths[] = {
4249
[UITableViewCellAccessoryNone] = 0,
@@ -45,9 +52,14 @@ - (CGFloat)fd_systemFittingHeightForConfiguratedCell:(UITableViewCell *)cell {
4552
[UITableViewCellAccessoryCheckmark] = 40,
4653
[UITableViewCellAccessoryDetailButton] = 48
4754
};
48-
accessroyWidth = systemAccessoryWidths[cell.accessoryType];
55+
rightSystemViewsWidth += systemAccessoryWidths[cell.accessoryType];
4956
}
50-
contentViewWidth -= accessroyWidth;
57+
58+
if ([UIScreen mainScreen].scale >= 3 && [UIScreen mainScreen].bounds.size.width >= 414) {
59+
rightSystemViewsWidth += 4;
60+
}
61+
62+
contentViewWidth -= rightSystemViewsWidth;
5163

5264

5365
// If not using auto layout, you have to override "-sizeThatFits:" to provide a fitting size by yourself.
@@ -79,7 +91,7 @@ - (CGFloat)fd_systemFittingHeightForConfiguratedCell:(UITableViewCell *)cell {
7991

8092
// Build edge constraints
8193
NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:cell attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
82-
NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:cell attribute:NSLayoutAttributeRight multiplier:1.0 constant:accessroyWidth];
94+
NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:cell attribute:NSLayoutAttributeRight multiplier:1.0 constant:-rightSystemViewsWidth];
8395
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:cell attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
8496
NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:cell attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
8597
edgeConstraints = @[leftConstraint, rightConstraint, topConstraint, bottomConstraint];

Demo/Demo/FDFeedViewController.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ - (void)configureCell:(FDFeedCell *)cell atIndexPath:(NSIndexPath *)indexPath {
9090
cell.entity = self.feedEntitySections[indexPath.section][indexPath.row];
9191
}
9292

93+
- (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView {
94+
return @[@"A",@"B",@"C",@"D"];
95+
}
96+
9397
#pragma mark - UITableViewDelegate
9498

9599
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

0 commit comments

Comments
 (0)