【发布时间】:2016-12-15 05:27:27
【问题描述】:
我有一个应用程序,我将集合视图单元格的宽度设为:
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(20, 20,20,20);
}
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGRect screenRect = collection.frame;
CGFloat screenWidth = screenRect.size.width;
float cellWidth = screenWidth / count;
}
但现在我想计算单元格的宽度需要依赖于一个参数,例如:
NSDictionary *dict=[arr objectAtIndex:indexPath.item];
float duration=([[dict valueForKey:@"duration"]floatValue]);
如果持续时间是 45,那么它需要占用屏幕宽度的 45%,就像这样。当我尝试screenWidth * (duration/100.0)它看起来像这样时,任何人都可以帮我解决这个问题
【问题讨论】:
-
float cellWidth = screenWidth / duration;试试这个
标签: ios iphone uicollectionview uicollectionviewlayout