UITableViewCellStyleSubtitle
has built-in support for self-sizing.
It will support an image, multi-line title, and a subtitle, without you needing to write or maintain any custom code to handle what it can already do.
Update:
Here is an example of using attributed text to take the place of 4 different "labels" for a subtitle:
In tableView:cellForIndexPath:
cell.detailTextLabel.attributedText = [self attributedTextForBookSources:sourcesValue];
Helper methods:
/**
The attributed text string corresponding to the referenced gospel books
@param sourcesValue An integer number representing a bitfield of gospel books that have source details for a pericope
@return The attributed string identifying the gospel book sources
*/
- (NSAttributedString *)attributedTextForBookSources:(NSInteger)sourcesValue
{
UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
UIColor *textcolor = [self textColorForPericopeSource:sourcesValue & CGIPericopeSourcesMatt];
NSMutableAttributedString *books = [[NSMutableAttributedString alloc] initWithString:@"Matt " attributes:@{NSFontAttributeName : font, NSForegroundColorAttributeName : textcolor}];
textcolor = [self textColorForPericopeSource:sourcesValue & CGIPericopeSourcesMark];
[books appendAttributedString:[[NSAttributedString alloc] initWithString:@" Mark " attributes:@{NSFontAttributeName : font, NSForegroundColorAttributeName : textcolor}]];
textcolor = [self textColorForPericopeSource:sourcesValue & CGIPericopeSourcesLuke];
[books appendAttributedString:[[NSAttributedString alloc] initWithString:@" Luke " attributes:@{NSFontAttributeName : font, NSForegroundColorAttributeName : textcolor}]];
textcolor = [self textColorForPericopeSource:sourcesValue & CGIPericopeSourcesJohn];
[books appendAttributedString:[[NSAttributedString alloc] initWithString:@" John" attributes:@{NSFontAttributeName : font, NSForegroundColorAttributeName : textcolor}]];
return [[NSAttributedString alloc] initWithAttributedString:books];
}
- (UIColor *)textColorForPericopeSource:(BOOL)included
{
return included ? [UIColor darkGrayColor] : [UIColor clearColor];
}
My code just hides or shows a book, but you may be able to also use an attributed string based on your four labels.
Anytime you can use the built-in styles, it generally means less code for you to write, maintain, and support, down the road, and more likelihood of it still working in a future version of iOS.
That app's cell self-sizes itself, and you see it can handle a multi-line title as you need.
