Skip to content

Commit

Permalink
[Example] Fixed cell height sizing on 6/6+
Browse files Browse the repository at this point in the history
  • Loading branch information
jhersh committed Jan 2, 2015
1 parent cf0f776 commit 6692322
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Example/AttributedTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
@property (nonatomic, copy) NSString *summaryText;
@property (nonatomic, strong) TTTAttributedLabel *summaryLabel;

+ (CGFloat)heightForCellWithText:(NSString *)text;
+ (CGFloat)heightForCellWithText:(NSString *)text availableWidth:(CGFloat)availableWidth;

@end
4 changes: 2 additions & 2 deletions Example/AttributedTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ - (void)drawRect:(CGRect)rect {
[self.summaryLabel setNeedsDisplay];
}

+ (CGFloat)heightForCellWithText:(NSString *)text {
+ (CGFloat)heightForCellWithText:(NSString *)text availableWidth:(CGFloat)availableWidth {
static CGFloat padding = 10.0;

UIFont *systemFont = [UIFont systemFontOfSize:kEspressoDescriptionTextFontSize];
CGSize textSize = CGSizeMake(275.0, CGFLOAT_MAX);
CGSize textSize = CGSizeMake(availableWidth - (2 * padding), CGFLOAT_MAX);
CGSize sizeWithFont = [text sizeWithFont:systemFont constrainedToSize:textSize lineBreakMode:NSLineBreakByWordWrapping];

#if defined(__LP64__) && __LP64__
Expand Down
6 changes: 4 additions & 2 deletions Example/RootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ - (NSInteger)tableView:(__unused UITableView *)tableView
return (NSInteger)[self.espressos count];
}

- (CGFloat)tableView:(__unused UITableView *)tableView
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(__unused NSIndexPath *)indexPath
{
return [AttributedTableViewCell heightForCellWithText:[self.espressos objectAtIndex:(NSUInteger)indexPath.row]];
return [AttributedTableViewCell heightForCellWithText:[self.espressos objectAtIndex:(NSUInteger)indexPath.row]
availableWidth:CGRectGetWidth(tableView.frame) - 26]; // rough accessory size
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";

AttributedTableViewCell *cell = (AttributedTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[AttributedTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Expand Down

0 comments on commit 6692322

Please sign in to comment.