我在其中我正在收集觀察室的寬度作爲應用:iOS中UIcollectionviewCell的動態寬度?
- (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;試試這個 –