Skip to content

Instantly share code, notes, and snippets.

@bobspryn
Created February 5, 2014 18:14
Show Gist options
  • Select an option

  • Save bobspryn/8829836 to your computer and use it in GitHub Desktop.

Select an option

Save bobspryn/8829836 to your computer and use it in GitHub Desktop.
static const CGFloat kLabelNegativePadding = 78;
static const CGFloat kLabelVerticalPadding = 17;
static const CGFloat kMinCellHeight = 61;
static const CGFloat kCellBorderInset = 8;
static UIFont *questionFont;
static UIFont *metaFont;
static UIFont *metaFontBold;
+ (void) setupFonts {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
questionFont = [UIFont fontWithDescriptor:[UIFontDescriptor preferredAvenirNextFontDescriptorWithTextStyle:UIFontTextStyleBody] size:0];
metaFontBold = [UIFont fontWithDescriptor:[[UIFontDescriptor preferredAvenirNextFontDescriptorWithTextStyle:UIFontTextStyleCaption2] fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold] size:0];
metaFont = [UIFont fontWithDescriptor:[UIFontDescriptor preferredAvenirNextFontDescriptorWithTextStyle:UIFontTextStyleCaption2] size:0];
});
}
+ (CGFloat) heightForCellWithTableWidth:(CGFloat)width withViewModel:(TCYouAskedQuestionCellViewModel *) viewModel {
[TCYouAskedQuestionCell setupFonts];
CGFloat widthForCalc = width - kLabelNegativePadding;
CGFloat height = [viewModel.question.questionText boundingRectWithSize:CGSizeMake(widthForCalc, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: questionFont} context:nil].size.height;
CGFloat metaHeight = [viewModel.question.authorFirstName boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:(NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName: metaFontBold} context:nil].size.height;
CGFloat totalHeight = height + metaHeight + kLabelVerticalPadding;
return totalHeight > kMinCellHeight ? totalHeight: kMinCellHeight;
}
- (void) layoutSubviews {
[super layoutSubviews];
self.questionLabel.preferredMaxLayoutWidth = self.contentView.frame.size.width - kLabelNegativePadding;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment