I have a UICollectionView as shown below.The titleLabel as you can see should vary its height as per the content.the background view labelView also should change its height.How can i do that?
i used...
-(CGFloat) heightForText:(NSString *)text withWidth:(CGFloat) textWidth{
CGSize constraint = CGSizeMake(textWidth, 20000.0f);
CGRect rect = [text boundingRectWithSize:constraint
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
attributes:@{NSFontAttributeName:cell.titleLabel.font}
context:nil];
CGFloat height = rect.size.height;
height = ceilf(height);
// NSLog(@"height %f", height);
return height;
}
i used this like ...
CGRect newFrame = cell.titleLabel.frame;
newFrame.size.height = height;
cell.titleLabel.frame = newFrame;
I am getting the new frame to the label.but the height increases from a fixed y towards down.Here now i have to lift the y according to the height.Is there any other way?