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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:53:00+00:00 2026-06-01T09:53:00+00:00

How would I go about dynamically adjusting the height of a UIScrollView ? Basically

  • 0

How would I go about dynamically adjusting the height of a UIScrollView? Basically I have a bunch of UILabels that are created (the exact number of UILabels is random) and the UIScrollView is to adjust its height automatically to accommodate the UILables. This is what I have thus far in the viewDidLoad.

- (void)viewDidLoad
{
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320
                                    , 1500)];
scroller.indicatorStyle = UIScrollViewIndicatorStyleWhite;
{ 

And this is the action that creates additional UILavels

-(IBAction)scheduale{
int i;
for(i=0; i<[self retrieveTime] ; i++){
    //Add time label
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.frame = CGRectMake(10, (i+1) * 21, 31, 20);
    timeLabel.textColor = [UIColor whiteColor];
    timeLabel.backgroundColor = [UIColor colorWithRed:76.0/225.0 green:76.0/225.0 blue:76.0/225.0 alpha:1.0];
    NSString *labelString;
    labelString = [[NSNumber numberWithInt:i] stringValue];
    timeLabel.text = labelString;
    timeLabel.textAlignment = UITextAlignmentCenter;
    //theLabel.tag = (i+1) * 100;
    [scroller addSubview:timeLabel];
}
  • 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-01T09:53:01+00:00Added an answer on June 1, 2026 at 9:53 am

    You need to hold onto a variable to keep track of how many labels you are adding and their height to set the content size when you are done creating labels. See adjusted code below:

    -(IBAction)scheduale{
    
     int i; 
     int contentSize = 0;
    
     for(i=0; i<[self retrieveTime] ; i++){
    
         UILabel *timeLabel = [[UILabel alloc] init];
         timeLabel.frame = CGRectMake(10, (i+1) * 21, 31, 20);
         contentSize += 20;
         timeLabel.textColor = [UIColor whiteColor];
         timeLabel.backgroundColor = [UIColor colorWithRed:76.0/225.0 green:76.0/225.0 blue:76.0/225.0 alpha:1.0];
         NSString *labelString;
         labelString = [[NSNumber numberWithInt:i] stringValue];
         timeLabel.text = labelString;
         timeLabel.textAlignment = UITextAlignmentCenter;
         //theLabel.tag = (i+1) * 100;
         [scroller addSubview:timeLabel]; }
    
     [scroller setContentSize:CGSizeMake(320, contentSize)];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC app that is basically one page with a bunch of
How would I go about dynamically allocating a multi-dimensional array?
How would I go about dynamically adding commas as a user is entering numbers?
How would I go about using an Expression Tree to dynamically create a predicate
I would like to know how I would go about altering the HTML that
I have links that load dynamically onto a background to make them look like
I have a question about how to dynamically generate JTrees. Is there a way
I hope many of you would have heard about Flipboard . One of the
I have about 500 images as resources in my app. First, is that a
I have a set of images that I would like to be aligned next

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.