2013-04-19 11 views
5

enter image description hereUICollectionView

में रजाई लेआउट बनाएँ मैं UICuollectionView.Each सेल के इस प्रकार की जरूरत है एक छवि है और एक label.The सेल ऊंचाई और चौड़ाई उस लेबल के पाठ पर निर्भर करता है।

- (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 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); 
} 

लेकिन मेरी कोशिकाएं निचोड़ रही हैं। enter image description here

क्या आप मुझे बता सकते हैं कि समस्या क्या है?

+0

आप ढांचे का उपयोग कर रहे करने के लिए एक GitHub लिंक पोस्ट कर सकते हैं? – Mundi

उत्तर

0

शायद तुम width टाइप किया जहां इस पंक्ति में height चाहता था:

[cell setFrame:CGRectMake(cell.frame.origin.x, 
          cell.frame.origin.y, 
          cell.frame.size.width, 
          cell.frame.size.width+f-20+10)]; 
+0

उत्तर के लिए धन्यवाद, हाँ आपने कहा कि ri8 बीटी अभी भी जारी है। मैंने चौड़ाई और ऊंचाई दी है। – Himanshu