Search code examples
iosobjective-cuicollectionviewautolayout

How can I move my cell in objective c for top and right


I am new to ios programming. here, I just wanted to move my cell little bit more right-hand side...and my top view is also covering the screen I wanted to reduce its size to fit correctly with the view..how can I achieve that


Solution

  • Use this lines of codes. Its going to fit your cells in collections as you looking for.

     - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
                CGFloat spaceBetweenCells = 5;
                CGFloat width = (yourMainView.frame.size.width - spaceBetweenCells) / 2;
                CGFloat height = (yourMainView.frame.size.height - spaceBetweenCells) / 2.5;
                return CGSizeMake(width, width*changeHeight+38 );
            }