Divyesh Savaliya Divyesh Savaliya - 1 year ago 133
Objective-C Question

label inside uicollectioviewcell taking frame after scroll

I am using collectionview in my app.
i have label inside my collectionviewcell.

i want to set frame to that label.

my code is

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath; {
menuCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.lblTag.frame = cell.contentView.frame;
cell.lblTag.text = [arrMenu objectAtIndex:indexPath.row];
return cell;


but this frame is works after i scroll collection view.

how can i reload collection view so that label frame set when collectionview display.

Answer Source

you can reload the collection view in viewDidAppear


    [self.yourcollectionView_outLet reloadData];

in my case it work for me.

you can try to change frame in main queue

dispatch_async(dispatch_get_main_queue(), ^{

           cell.lblTag.frame = cell.contentView.frame;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download