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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:55:06+00:00 2026-05-28T03:55:06+00:00

In my project I have a simple UIView with a UIScrollView subview. I am

  • 0

In my project I have a simple UIView with a UIScrollView subview. I am trying to calculate the height based on the content within the UIScrollView with the following code:

enter image description here

file.h

@interface ScrollViewController : UIViewController {
IBOutlet UILabel* topLabel;
IBOutlet UILabel* bottomLabel;
    IBOutlet UIScrollView * scroller;   
} 

@property(nonatomic,retain) IBOutlet UIScrollView *scroller;

file.m

- (void)viewDidLoad {
    [scroller setScrollEnabled:YES];
    CGFloat scrollViewHeight = 0.0f;
    for (UIView* view in scroller.subviews)
    {
       scrollViewHeight += view.frame.size.height;
    }
    // print value 88.000000
    NSLog(@"%f", scrollViewHeight);
    [scroller setContentSize:CGSizeMake(320, scrollViewHeight)];
    [super viewDidLoad];
}

I don’t know why the code doesn’t work.

  • 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-28T03:55:06+00:00Added an answer on May 28, 2026 at 3:55 am

    Well, a couple things. First, set a breakpoint at the beginning of that method and walk through your code one line at a time to see what it’s doing.

    Second, Depending on how your views are laid out, especially if you have views next to each other, that code might not work. It’ll also not work if there is vertical margin/space in between the subviews. Instead, you might try this code when looping through the subviews:

    for (UIView *view in scroller.subviews){
        if (scrollViewHeight < view.frame.origin.y + view.frame.size.height) scrollViewHeight = view.frame.origin.y + view.frame.size.height;
    }
    

    This should get you the correct height.

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

Sidebar

Related Questions

Currently I have a simple maven project that is building a jar file and
In a Flex Mobile project I have a simple itemRenderer where I'm trying to
I have an iPhone project that starts out with a standard UIView based Window...
I have a simple spring3,hibernate 3 project.When am trying to build the project using
I'd like to try out the D programming language. I have simple pet project
I have a simple Scala project that runs without any problems inside Eclipse, however,
I have this simple test project just to test the IncludeExceptionDetailInFaults behavior. public class
In my simple project I have 2 views - a line item view (Brand)
I have a simple java project (adapted from the example here ), which is
I have a simple task. I have an existing project with a web service

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.