casillas casillas - 3 months ago 11
iOS Question

CollectionView Horizontally - the last Image out of screen

I am trying to achieve to upload images up to five from camera/gallery on a collection view which is only 1xN horizontally. However, when I have more than 3 images, the last images is not shown properly, it is partially seen.

In the following image, please pay attention to camera icon, which is partially out of screen. I am testing with iPhone 5s.

I have put this small project in the following repository: https://github.com/texas16/CameraCollectionView

enter image description here

Answer

I have checked your project, In this method

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

Your problem is you have used "<"

 [aBlockSelf.arrayOfImages replaceObjectAtIndex:self.selectedPath.row withObject:chosenImage];
    if([aBlockSelf.arrayOfImages count] < NUMBER_OF_IMAGES)
    {
        [aBlockSelf.arrayOfImages addObject:[UIImage imageNamed:@"photo.png"]];
    }

but that's why camera image not appearing at last cell so u have to used "<= "

[aBlockSelf.arrayOfImages replaceObjectAtIndex:self.selectedPath.row withObject:chosenImage];
    if([aBlockSelf.arrayOfImages count] <= NUMBER_OF_IMAGES) // use <=
    {
        [aBlockSelf.arrayOfImages addObject:[UIImage imageNamed:@"photo.png"]];
    }

and also you have not set your constrain or else if you don't want to use autoLayout you need to use Auto-resize

Check this example (Using Autolayout)

5s Screenshot

enter image description here

Using Auto resize

enter image description here