小编Him*_*shu的帖子

在UICollectionView中创建Quilt布局

在此输入图像描述

我需要这种类型的UICuollectionView.Each单元格有一个图像和一个标签.单元格的高度和宽度取决于该标签的文本.

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:          (NSIndexPath *)indexPath {

   CollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"kCellID"  forIndexPath:indexPath];
if(cell == nil){
    cell = [[[NSBundle mainBundle] loadNibNamed:@"CollectionViewCell" owner:self options:nil] lastObject];
}
cell.backgroundColor = [UIColor redColor];
cell.image.image = [UIImage imageNamed:[self.arrPhotos objectAtIndex:indexPath.row]];
[cell.image setFrame:CGRectMake(cell.image.frame.origin.x, cell.image.frame.origin.y, cell.image.frame.size.width,100)];
float f = [self getHeightCalculateForTheText:[arrText objectAtIndex:indexPath.row]  andwidth:96];
[cell.label setFrame:CGRectMake(0,100,96, f)];
cell.label.text = [arrText objectAtIndex:indexPath.row];
[cell setFrame:CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.width+f-20+10)];
return cell;
}

- (CGSize) blockSizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row >= self.arrPhotos.count)
    NSLog(@"Asking for index paths of non-existant cells!! %d from %d …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios ios6 uicollectionview

5
推荐指数
1
解决办法
1392
查看次数

标签 统计

ios ×1

ios6 ×1

iphone ×1

objective-c ×1

uicollectionview ×1