Aryan Kashyap
Aryan Kashyap

Reputation: 121

UICollectionView Vertical showing half the cell in the end

i have collectionView. it shows cell in vertically.

in the start the collectionView looks like this

start of the collectionview enter image description here

at the end it looks like this

end of collectionView enter image description here

so it basically doesnt show up the whole cell in the end the code for collection class is

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

 }

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - CollectionView Datasource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 9;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ViewControllerCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];



    return cell;
}
@end

Upvotes: 1

Views: 1114

Answers (3)

Vasanthan Prem
Vasanthan Prem

Reputation: 195

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

float width = 100;  //change to your needed width
float height = 100;  //change to your needed height

return CGSizeMake(width, height);

}

Upvotes: 1

Abhinandan Pratap
Abhinandan Pratap

Reputation: 2148

try this code it will help you

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 9;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cellIdentifier";
    UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    return cell;
}

and change identifier name in attribute inspector as shown in image:

enter image description here

Upvotes: 0

Najj
Najj

Reputation: 31

You have to specify the cell size in your storyboard.

Upvotes: 1

Related Questions