2016-03-30 8 views
1

Bitte helfen ... dieser Code über das Label fahren wird ....Etikettenüberschreibung in uicollectionview in Objective C

cellForItemAtIndexPath

static NSString *identifier = @"cellIdentifier"; 

[self.mycollectionViewOutlet registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"]; 

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 

cell.backgroundColor =[UIColor greenColor]; 

self.mycollectionViewOutlet.backgroundColor=[UIColor redColor]; 

objects_products * ob = [self.recipeImages objectAtIndex:indexPath.row]; 

UILabel *recipelableView = (UILabel*)[cell.contentView viewWithTag:LABEL_TAG]; 

if (!recipelableView) 

     recipelableView=[[UILabel alloc]initWithFrame:CGRectMake(50,115,100,50)]; 

     [recipelableView setFont:[UIFont fontWithName:@"HelveticaNeue" size:12]]; 

     recipelableView.textColor=[UIColor redColor]; 

     [recipelableView setText:ob.price]; 

     recipelableView.tag = LABEL_TAG; 

     [cell addSubview:recipelableView]; 

    return cell; 
+0

R U mit einer Coustom-Zelle? –

+0

Was ist dein Problem? ist auch der Code, den Sie in CellForItemAt eingefügt haben ...? –

Antwort

0

sein kann es Ihnen helfen, kannst du mehr Male Label zu Zelle. Bitte fügen Sie das Etikett der Zelle in Zustand (es wurde nur einmal hinzugefügt) wie folgt hinzu.

static NSString *identifier = @"cellIdentifier"; 

[self.mycollectionViewOutlet registerClass:[UICollectionViewCell class]  forCellWithReuseIdentifier:@"cellIdentifier"]; 

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 

cell.backgroundColor =[UIColor greenColor]; 

self.mycollectionViewOutlet.backgroundColor=[UIColor redColor]; 

objects_products * ob = [self.recipeImages objectAtIndex:indexPath.row]; 

UILabel *recipelableView = (UILabel*)[cell.contentView viewWithTag:LABEL_TAG]; 

if (!recipelableView) { 
    recipelableView=[[UILabel alloc]initWithFrame:CGRectMake(50,115,100,50)]; 
    [recipelableView setFont:[UIFont fontWithName:@"HelveticaNeue" size:12]]; 

    recipelableView.textColor=[UIColor redColor]; 
    recipelableView.tag = LABEL_TAG; 
    [cell addSubview:recipelableView]; 
} 


    [recipelableView setText:ob.price]; 

    return cell;