diff --git a/Example/AttributedTableViewCell.h b/Example/AttributedTableViewCell.h index 9b2ee4f1..59543f62 100644 --- a/Example/AttributedTableViewCell.h +++ b/Example/AttributedTableViewCell.h @@ -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 diff --git a/Example/AttributedTableViewCell.m b/Example/AttributedTableViewCell.m index a2fd8abf..56679801 100644 --- a/Example/AttributedTableViewCell.m +++ b/Example/AttributedTableViewCell.m @@ -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__ diff --git a/Example/RootViewController.m b/Example/RootViewController.m index 6f849332..d6573782 100644 --- a/Example/RootViewController.m +++ b/Example/RootViewController.m @@ -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;