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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:40:54+00:00 2026-06-08T12:40:54+00:00

I am adding subviews to my scrollview according to the number of array elements

  • 0

I am adding subviews to my scrollview according to the number of array elements in a for loop.The container view has an additional subview inside.The problem is that only the first container views contains the added subview and the new one does not but the third one also has it.I checked the Frame of the subviews but still does not seem to work.

CGFloat contentOffset = 0.0f;
//add tej views one by one to scrollview

for (NSString *packageType in packageTypesArray) 
{

    CGRect lvPackageContainerFrame = CGRectMake(contentOffset, 0.0f,scrollView.frame.size.width,scrollView.frame.size.height);

    LVPackageContainer *lvPackageContainer = [[LVPackageContainer alloc] initWithFrame:lvPackageContainerFrame];

    NSLog(@"Frame %@",NSStringFromCGRect(lvPackageContainerFrame));
    lvPackageContainer.packageType = packageType;
    [packageContainersArray addObject:lvPackageContainer];

     UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 264, 314)];
     NSLog(@"BackgroundImage %@",backgroundImage);
     backgroundImage.backgroundColor = [UIColor redColor];
     [backgroundImage setImage:[UIImage imageNamed:@"shadowBackground.png"]];
     backgroundImage.center = lvPackageContainer.center;
     [lvPackageContainer addSubview:backgroundImage];


    [scrollView addSubview:lvPackageContainer];

    contentOffset += lvPackageContainerFrame.size.width;
    scrollView.contentSize = CGSizeMake(contentOffset, scrollView.frame.size.height);

}   
  • 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-08T12:40:55+00:00Added an answer on June 8, 2026 at 12:40 pm
    backgroundImage.center = CCGPointMake(lvPackageContainerFrame.size.width/2, lvPackageContainerFrame.size.height/2);
    

    If you add a subview, the coordinate system is start from its parent view

    In your case, when you set center for second view, it will become something like {480,240} (Assuming the view is full screen in iphone)
    So, the 3rd one subview you can see the is actually the subview of page 2.

    Updated:
    When you get the center of a view, it actually calculate from the frame values:

    center.x = (frame.origin.x + frame.size.width) / 2;
    center.y = (frame.origin.y + frame.size.height) / 2;
    

    Therefore assume your second view is with CGRectMake(320, 0, 320, 480), the center of it will be

    center.x = (320 + 320) / 2;
    center.y = (0 + 480) / 2;
    

    So your subview will be center at {480,240} of the second view.

    If you convert it relative to the scrollview, the subview will be at {(320+480),(0+240)}, which you will see it is on the 3rd view, not the 2nd one

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

Sidebar

Related Questions

In my iPhone/iPad app, I am adding one subview to my main view. This
I'm adding a UITableView as a subview to my view; it's a subview because
I am adding uiimageview as a subview to tabbarcontroller.view. when i pushed to other
I am adding Uiimageview as a subview to tabbarcontroller.view. when i pushed to other
I've got a button that I'm adding as a subview of a table view's
I have a somewhat transparent view (alpha = 0.6) that has some subviews. I'd
I'm having problems adding subviews to a scrollview sequentially. I've got a JSON response
I'm subclassing UITableViewCell and adding two subviews (image, UILabel). When the row is touched.
I'm adding some UITextFields, UITextViews and UIImageViews as subviews to a UITableCell. When I'm
I have subclassed a UIView . I am adding it as a subview of

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.