Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8586719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:22:45+00:00 2026-06-11T22:22:45+00:00

I have a UIScrollView with paging enabled. I want to full it with images

  • 0

I have a UIScrollView with paging enabled. I want to full it with images and I have a UIImageView which needs to be made to fit without using .frame. This is because it doesn’t work with Autolayout enabled. Not using Autolayout isn’t an option.

Here’s the code as it stands:

//Prepare and load the view
[scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), (kScrollObjHeight))];
scrollView1.pagingEnabled = YES;
[scrollView1 setShowsHorizontalScrollIndicator:NO];

CGRect Rect = scrollView1.bounds;
UIImageView *beadContainer;

for (int i = 0; i < imageViews.count; i++)
{
    beadContainer = [imageViews objectAtIndex:i];
    beadContainer.frame = Rect;
    [scrollView1 addSubview:beadContainer];
    Rect.origin.x += Rect.size.width;
}

None of the images appear as it stands, though the ScrollView has all of the right dimensions and scrolls as expected. If I comment out beadContainer.frame = Rect;, then all of the images in the array imageViews appear at 0, 0. They all show up on top of one another. Of course, I need them to fill the ScrollView.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:22:47+00:00Added an answer on June 11, 2026 at 10:22 pm

    Why don’t you use autolayout to layout the images?

    //Prepare and load the view
    [scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), (kScrollObjHeight))];
    scrollView1.pagingEnabled = YES;
    [scrollView1 setShowsHorizontalScrollIndicator:NO];
    
    
    
    UIImageView *firstImage = imageViews[0];
    UIImageView *lastImageView = [imageViews lastObject];
    UIImageView *previousImageView = nil;
    NSMutableArray *constraints = [NSMutableArray new];
    for (UIImageView *imageView in imageViews){
        [scrollView1 addSubview:imageView];
        //set the size of the images
        [constraints addObject:[NSLayoutConstraint constraintWithItem:imageView
                                                            attribute:NSLayoutAttributeWidth
                                                            relatedBy:NSLayoutRelationEqual
                                                               toItem:nil
                                                            attribute:NSLayoutAttributeNotAnAttribute
                                                           multiplier:1.0f
                                                             constant:kScrollObjWidth]];
        [constraints addObject:[NSLayoutConstraint constraintWithItem:imageView
                                                            attribute:NSLayoutAttributeHeight
                                                            relatedBy:NSLayoutRelationEqual
                                                               toItem:nil
                                                            attribute:NSLayoutAttributeNotAnAttribute
                                                           multiplier:1.0f
                                                             constant:kScrollObjHeight]];
        //remove autoresizing masks
        [imageView setTranslatesAutoresizingMaskIntoConstraints:NO];
        //pin the top of the imageview to the top of the superview
        [constraints addObjectsFromArray:[NSLayoutConstraint constraintWithVisualFormat:@"V:|[imageView]"
                                                                                options:0
                                                                                metrics:nil
                                                                                  views:NSDictionaryOfVariableBindings(imageView)]];
    
        if ([firstImage isEqual:imageView]){ //pin the first image view to the left of the scrollview
            [constraints addObjectsFromArray:[NSLayoutConstraint constraintWithVisualFormat:@"|[firstImage]"
                                                                                    options:0
                                                                                    metrics:nil
                                                                                      views:NSDictionaryOfVariableBindings(firstImage)]];
        }
    
        if (previousImageView){ //pin any imageViews to the previous imageViews
            [constraints addObjectFromArray:[NSLayoutConstraint constraintWithVisualFormat:@"[previousImageView][imageView]"
                                                                                   options:0
                                                                                   metrics:nil
                                                                                     views:NSDictionaryOfVariableBindings(imageView, previousImageView)]];
        }
        previousImageView = imageView;
    }
    
    [scrollView1 addConstraints:constraints];
    

    Mind you I haven’t tried this, it might be rubbish code, I wrote it in a text editor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIScrollView with paging enabled, and that works fine. Now I want
I have a UIScrollView with ten UIView s in it and paging enabled. On
I have a UIScrollview with paging enabled. There are 3 views (pages) inside this
I need to display 10 - 1000 images on a UIScrollView. Paging is enabled.
I have a scrollView with paging enabled and a number N of pages, which
I have a UIScrollView that contains a UIView inside. The UIScrollView has paging enabled
I have a UIScrollView with paging enabled. Each page is of width 768.0px in
I have a UIScrollView 's paging enabled and set its clipToBounds = NO so
I have a UIScrollView with pagingEnabled on and I want to (using like a
I have a UIScrollView with paging enabled. After I change the view from landscape

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.