using UIScrollView to swipe through images

pelisterpelister USMember ✭✭

hi. I have a table view with custom UITableViewCell which contains a square UIScrollView as wide as the table view. the scroll view will be used for horizontally swiping through an array of images up to 5 items.

I created the cell design in Xcode, the checkboxes of UIScrollView for "Scrolling Enabled" and "Paging Enabled" are checked. as for the scroll indicators, I only checked "Shows Horizontal Indicator".

Now I am trying to populate the scroll view with image views, my problem is that only the first image is displayed with the below code:

byte[][] buffers = ...; for (int i = 0; i < buffers.Length; i++) { var img = new UIImageView(new UIImage(NSData.FromArray(buffers[i]))); img.ContentMode = UIViewContentMode.ScaleAspectFill; PhotosScrollView.AddSubview(img); } PhotosScrollView.ContentSize = new CGSize(this.PhotosScrollView.Frame.Size.Width * buffers.Length, this.PhotosScrollView.Frame.Size.Height);

I am new to iOS and I cannot figure out what causes the rest of the images not showing up. any ideas would be highly appreciated!

Answers

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    @ugurpelister,

    I believe the issue is because of this:

    PhotosScrollView.AddSubview(img);
    

    This is basically adding each image on top of the previous one which is not what you want. You may be interested in the approach used in this sample.

Sign In or Register to comment.