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 6559861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:23:03+00:00 2026-05-25T13:23:03+00:00

I am trying to display 3 UIScrollViewControllers in the same window as 3 horizontal

  • 0

I am trying to display 3 UIScrollViewControllers in the same window as 3 horizontal stripes 3 times the screen wide scrolling indipendently. The code to achieve this is below but for some reason it doesn’t work, showing only the upper stripe.

With the help of the additional white background view I placed on the window I can see the other 2 regions of the screen are scrollable as well, but for some reason their background color is not showing up…I can’t figure out why.

Here is the code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Creating the window programmatically
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

   CGRect bounds = [self window].bounds;

    float x = bounds.origin.x;
    float y = bounds.origin.y;
    float w = bounds.size.width;
    float h = bounds.size.height;

    CGRect upperFrame = CGRectMake(x,y,w,h/3);
    CGRect middleFrame = CGRectMake(x,y + h/3,w,h/3);
    CGRect lowerFrame = CGRectMake(x, y + 2 * h/3, w, h/3);

    // Creating the scroll view which will contain the 3 views
    UIScrollView *upperScrollView = [[UIScrollView alloc] initWithFrame:upperFrame];
    UIScrollView *middleScrollView = [[UIScrollView alloc] initWithFrame:middleFrame];
    UIScrollView *lowerScrollView = [[UIScrollView alloc] initWithFrame:lowerFrame];

    // ContentSize should be wide enough for 3 pages
    [upperScrollView setContentSize:CGSizeMake(3 * w, h/3)];
    [middleScrollView setContentSize:CGSizeMake(3 * w, h/3)];
    [lowerScrollView setContentSize:CGSizeMake(3 * w, h/3)];

    // Enforce the display of only one page at a time
    [upperScrollView setPagingEnabled:YES];
    [middleScrollView setPagingEnabled:YES];
    [lowerScrollView setPagingEnabled:YES];

    // UPPER SCROLLVIEW

    // This will be the first view (red)
    UIView *redViewU = [[UIView alloc] initWithFrame:upperFrame];
    [redViewU setBackgroundColor:[UIColor redColor]];

    // The second view will start horizontally when the first view ends
    upperFrame.origin.x += w;

    // This will be the second view (green)
    UIView *greenViewU = [[UIView alloc] initWithFrame:upperFrame];
    [greenViewU setBackgroundColor:[UIColor greenColor]];

    // The third view will start horizontally when the second view ends
    upperFrame.origin.x += w;

    // This will be the third view (blue)
    UIView *blueViewU = [[UIView alloc] initWithFrame:upperFrame];
    [blueViewU setBackgroundColor:[UIColor blueColor]];

    // Adding the 3 views to the scroll view
    [upperScrollView addSubview:redViewU];
    [upperScrollView addSubview:greenViewU];
    [upperScrollView addSubview:blueViewU];

    // Now creating the view controller, father of the scrollview
    UIViewController *upperViewController = [[UIViewController alloc] init];
    [upperViewController setView:upperScrollView];

    // MIDDLE SCROLLVIEW

    // This will be the first view (red)
    UIView *redViewM = [[UIView alloc] initWithFrame:middleFrame];
    [redViewM setBackgroundColor:[UIColor redColor]];

    // The second view will start horizontally when the first view ends
    middleFrame.origin.x += w;

    // This will be the second view (green)
    UIView *greenViewM = [[UIView alloc] initWithFrame:middleFrame];
    [greenViewM setBackgroundColor:[UIColor greenColor]];

    // The third view will start horizontally when the second view ends
    middleFrame.origin.x += w;

    // This will be the third view (blue)
    UIView *blueViewM = [[UIView alloc] initWithFrame:middleFrame];
    [blueViewM setBackgroundColor:[UIColor blueColor]];

    // Adding the 3 views to the scroll view
    [middleScrollView addSubview:redViewM];
    [middleScrollView addSubview:greenViewM];
    [middleScrollView addSubview:blueViewM];

    // Now creating the view controller, father of the scrollview
    UIViewController *middleViewController = [[UIViewController alloc] init];
    [middleViewController setView:middleScrollView];

    // LOWER SCROLLVIEW

    // This will be the first view (red)
    UIView *redViewL = [[UIView alloc] initWithFrame:lowerFrame];
    [redViewL setBackgroundColor:[UIColor redColor]];

    // The second view will start horizontally when the first view ends
    lowerFrame.origin.x += w;

    // This will be the second view (green)
    UIView *greenViewL = [[UIView alloc] initWithFrame:lowerFrame];
    [greenViewL setBackgroundColor:[UIColor greenColor]];

    // The third view will start horizontally when the second view ends
    lowerFrame.origin.x += w;

    // This will be the third view (blue)
    UIView *blueViewL = [[UIView alloc] initWithFrame:lowerFrame];
    [blueViewL setBackgroundColor:[UIColor blueColor]];

    // Adding the 3 views to the scroll view
    [lowerScrollView addSubview:redViewL];
    [lowerScrollView addSubview:greenViewL];
    [lowerScrollView addSubview:blueViewL];

    // Now creating the view controller, father of the scrollview
    UIViewController *lowerViewController = [[UIViewController alloc] init];
    [lowerViewController setView:lowerScrollView];

    // A white background view to see at least the scroll indicators
    UIView *whiteView = [[UIView alloc] initWithFrame:bounds];
    [whiteView setBackgroundColor:[UIColor whiteColor]];

    // Finally the window will hold the view controllers' views
    [[self window] addSubview:whiteView];
    [[self window] addSubview:upperViewController.view];
    [[self window] addSubview:middleViewController.view];
    [[self window] addSubview:lowerViewController.view];

    // Displaying the window
    [self.window makeKeyAndVisible];
    return YES;
}
  • 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-05-25T13:23:04+00:00Added an answer on May 25, 2026 at 1:23 pm

    Solved: after succeeding doing the same thing with IB I realized that for some reason the views inside the UIScrollView want RELATIVE x,y coordinates for their frames, not ABSOLUTE.

    Changing the frames of the views in the above code with the following (the same for every UIScrollView):

    CGRect redViewFrame = CGRectMake(x,y,w,h/3);
    CGRect greenViewFrame = CGRectMake(w,y,w,h/3);
    CGRect blueViewFrame = CGRectMake(2 * w,y,w,h/3);
    

    solved the issue, and now I can see the 3 scrolling backgrounds.
    Hope it helps someone else 🙂 I am done, for now.

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

Sidebar

Related Questions

Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
Im trying to display a loading gif before submitting a multipart-form (file upload), this
Im trying to display this listview, but I keep getting a: 07-17 21:14:22.233: ERROR/AndroidRuntime(349):
I am trying to display random images heres my code private void Page_Load(object sender,
I'm trying to display those rows in my DataGrid, which share the same column-value.
When trying to display a byte stream from HLDS (Half-Life Dedicated Server) in a
I've been trying to display text using a Quartz context, but no matter what
I'm trying to display a series of titles varying from 60 characters to 160
I am trying to display a list of all files found in the selected
I'm trying to display a loading icon while my iPhone app downloads a network

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.