iphone - Create Quilt Layouts in UICollectionView -

i need type of uicuollectionview.each cell have 1 image , label.the cell height , width depends on text of label.
- (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 index paths of non-existant cells!! %d %d cells", indexpath.row, self.arrphotos.count); float f = [self getheightcalculateforthetext:[arrtext objectatindex:indexpath.row] andwidth:96]; if (f > 0 && f< 30) return cgsizemake(1, 2); else if (f > 30 && f< 60) return cgsizemake(1, 3); else if (f > 60 && f< 90) return cgsizemake(1, 4); else if (f > 90 && f< 120) return cgsizemake(1, 5); else if (f > 120 && f< 150) return cgsizemake(1, 6); else if(f > 150 && f< 180) return cgsizemake(1, 7); return cgsizemake(1,1); } but cells getting squeezed.
can me know what's problem is?
maybe typed width wanted height in line:
[cell setframe:cgrectmake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.width+f-20+10)];
Comments
Post a Comment