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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:34:03+00:00 2026-05-31T08:34:03+00:00

I can add several scrollviews with its background colours changed and it works fine.

  • 0

I can add several scrollviews with its background colours changed and it works fine. So basically for every view you have different background colours. However when I try to add separate views for each of these, it adds it right on top of the other and I don’t know why.

UIViewController *view1 = [self.storyboard instantiateViewControllerWithIdentifier:@"View1"];
UIViewController *view2 = [self.storyboard instantiateViewControllerWithIdentifier:@"View2"];
UIViewController *view3 = [self.storyboard instantiateViewControllerWithIdentifier:@"View3"];


for (NSInteger i=0; i<ScrollViewControllerNumberOfPages; i++) {
    CGFloat yOrigin = i * self.view.frame.size.height;
    CGRect subViewFrame = CGRectMake(yOrigin, 0, pageHeight, pageWidth);
    NSLog(@"Printing Width and Height %f  %f",pageWidth,pageHeight);
    UIView *subView = [[UIView alloc] initWithFrame:subViewFrame];

    // Pick a random colour for the view
    CGFloat randomRed = ((CGFloat)(arc4random() % 1000))/1000;
    CGFloat randomGreen = ((CGFloat)(arc4random() % 1000))/1000;
    CGFloat randomBlue = ((CGFloat)(arc4random() % 1000))/1000;
    subView.backgroundColor = [UIColor colorWithRed:randomRed green:randomGreen blue:randomBlue alpha:1];
    NSLog(@"printin i %i", i);
    if (i == 0)
    subView = view1.view;
    else if (i == 1)
        subView = view2.view;
[self.scrollView addSubview:subView];
}
  • 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-31T08:34:04+00:00Added an answer on May 31, 2026 at 8:34 am

    This is kind of a shot in the dark because your code would need some serious rethinking.

    What you’re doing is you allocate a subview, you modify it’s frame and background and then completely disregard this and set it to a view of previously instantiated viewcontoller.

    This should work (in a way):

    UIViewController *view1 = [self.storyboard instantiateViewControllerWithIdentifier:@"View1"];
    UIViewController *view2 = [self.storyboard instantiateViewControllerWithIdentifier:@"View2"];
    UIViewController *view3 = [self.storyboard instantiateViewControllerWithIdentifier:@"View3"];
    
    for (NSInteger i=0; i<ScrollViewControllerNumberOfPages; i++) {
        CGFloat yOrigin = i * self.view.frame.size.height;
        CGRect subViewFrame = CGRectMake(yOrigin, 0, pageHeight, pageWidth);
        NSLog(@"Printing Width and Height %f  %f",pageWidth,pageHeight);
    
        UIView *subView;
    
        if (i == 0)
          subView = view1.view;
        else if (i == 1)
          subView = view2.view;
    
        subView.frame = subViewFrame;
    
        // Pick a random colour for the view
        CGFloat randomRed = ((CGFloat)(arc4random() % 1000))/1000;
        CGFloat randomGreen = ((CGFloat)(arc4random() % 1000))/1000;
        CGFloat randomBlue = ((CGFloat)(arc4random() % 1000))/1000;
        subView.backgroundColor = [UIColor colorWithRed:randomRed green:randomGreen blue:randomBlue alpha:1];
        NSLog(@"printin i %d", i);
        [self.scrollView addSubview:subView];
    }
    

    It might look a bit better if you do it like:

    for (NSInteger i=0; i<ScrollViewControllerNumberOfPages; i++) {
        CGFloat yOrigin = i * self.view.frame.size.height;
        CGRect subViewFrame = CGRectMake(yOrigin, 0, pageHeight, pageWidth);
        NSLog(@"Printing Width and Height %f  %f",pageWidth,pageHeight);
    
        UIViewController *subViewCont = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"View%d",i+1]];
    
        UIView *subView = subViewCont.view;
    
        subView.frame = subViewFrame;
    
        // Pick a random colour for the view
        CGFloat randomRed = ((CGFloat)(arc4random() % 1000))/1000;
        CGFloat randomGreen = ((CGFloat)(arc4random() % 1000))/1000;
        CGFloat randomBlue = ((CGFloat)(arc4random() % 1000))/1000;
        subView.backgroundColor = [UIColor colorWithRed:randomRed green:randomGreen blue:randomBlue alpha:1];
        NSLog(@"printin i %d", i);
        [self.scrollView addSubview:subView];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please help me with how I can add several different queries to
I have several forms(user can add new form dynamically) in one page, they're all
I'd like to add several different user types to my rails application. I have
I have a LinearLayout view that already contains several elements. I want to add
I have a java applet that loads up a scroll view that you can
I have a screen which allows users to add several categories at once. They
I have extended the Mage_Adminhtml_Block_Sales_Order_Grid class with a custom module to add several customer
On several phones like a Nexus or a HTC phone you can add a
I have a listview where I add several columns: LVCOLUMN column; column.mask = LVCF_FMT
i have an iPhone app in which i have several images. These images add

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.