//计算集合视图的高度
- (CGFloat)calculateHeightOfCollectionViewForTexts:(NSArray*)texts{
//集合视图的宽度
CGFloat viewWidth = SCREEN_WIDTH - 12 - 12;
//设置文本之间的间隔
CGFloat textInterval = 10.f;
//计算多个文本宽度和
CGFloat textWidthSum = textInterval;
//设置文本的行高
CGFloat textHeight = 34.f;
//设置文本计数
NSInteger textCount = 0;
//记录行数
NSInteger numberRow = 0;
for (NSString *str in texts) {
textCount ++;
textWidthSum = textWidthSum + [self calculateWidthOfTextForStr:str] + textInterval;
if (textWidthSum > viewWidth) {
numberRow ++;
textWidthSum = textInterval + [self calculateWidthOfTextForStr:str];
textCount = 1;
}
if ([str isEqualToString:texts.lastObject]) {
numberRow ++;
}
}
return textHeight*numberRow + 10*(numberRow-1) + 20;
}