In my application I have multiple tableviews with custom cells. Some of the text in the cells are spread out on between 2-4 lines so the height of the label is large enough
In iOS 7 sizeWithFont: is now deprecated!
Several solutions like subclassing UILabel have to be adapted.
My solution for top aligned label text:
In a subclass TopVerticalAlignmentLabel : UILabel override drawRect: as follows:
- (void)drawRect:(CGRect)rect
{
CGRect labelStringRect = [self.text boundingRectWithSize:CGSizeMake(self.frame.size.width, CGFLOAT_MAX)
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
attributes:@{ NSFontAttributeName: self.font, /* further attributes */}
context:nil];
[super drawTextInRect:CGRectMake(0, 0, self.frame.size.width, labelStringRect.size.height)];
}