Skip to content

Commit bbff3bb

Browse files
committed
Fix iOS test app detail text label.
1 parent 760dedc commit bbff3bb

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

Example/Classes/Views/PostTableViewCell.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,17 @@ - (void)setPost:(Post *)post {
5757
}
5858

5959
+ (CGFloat)heightForCellWithPost:(Post *)post {
60+
CGFloat desiredHeight = fmaxf(70.0f, (float)[self detailTextHeight:post.text] + 45.0f);
61+
62+
return desiredHeight;
63+
}
64+
65+
+ (CGFloat)detailTextHeight:(NSString *)text {
6066
#pragma clang diagnostic push
6167
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
62-
CGSize sizeToFit = [post.text sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:CGSizeMake(220.0f, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];
68+
CGSize sizeToFit = [text sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:CGSizeMake(240.0f, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];
6369
#pragma clang diagnostic pop
64-
return fmaxf(70.0f, (float)sizeToFit.height + 45.0f);
70+
return sizeToFit.height;
6571
}
6672

6773
#pragma mark - UIView
@@ -70,10 +76,11 @@ - (void)layoutSubviews {
7076
[super layoutSubviews];
7177

7278
self.imageView.frame = CGRectMake(10.0f, 10.0f, 50.0f, 50.0f);
73-
self.textLabel.frame = CGRectMake(70.0f, 10.0f, 240.0f, 20.0f);
79+
self.textLabel.frame = CGRectMake(70.0f, 6.0f, 240.0f, 20.0f);
7480

7581
CGRect detailTextLabelFrame = CGRectOffset(self.textLabel.frame, 0.0f, 25.0f);
76-
detailTextLabelFrame.size.height = [[self class] heightForCellWithPost:self.post] - 45.0f;
82+
CGFloat calculatedHeight = [[self class] detailTextHeight:self.post.text];
83+
detailTextLabelFrame.size.height = calculatedHeight;
7784
self.detailTextLabel.frame = detailTextLabelFrame;
7885
}
7986

0 commit comments

Comments
 (0)