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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:35:58+00:00 2026-06-16T11:35:58+00:00

I have a UIViewController , and I want to add a UIScrollView to it

  • 0

I have a UIViewController, and I want to add a UIScrollView to it (enable scroll support), is it possible?

I know it is possible, if you have a UIScrollView to add a UIViewController to it, but I’m interested also if reverse was true, if I cann add a UIScrollView to an existing UIViewController, such that I get scrolling feature.

Edit

I think I have found an answer: Adding a UIViewController to UIScrollView

  • 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-16T11:35:59+00:00Added an answer on June 16, 2026 at 11:35 am

    An UIViewController has a view property. So, you can add a UIScrollView to its view. In other words, you can add the scroll view to the view hierarchy.

    This is can achieved by code or through XIB. In addition, you can register the view controller as the delegate for your scroll view. In this way, you can implement methods for performing different functionalities. See UIScrollViewDelegate protocol.

    // create the scroll view, for example in viewDidLoad method
    // and add it as a subview for the controller view
    
    [self.view addSubview:yourScrollView];
    

    You could also override loadView method for UIViewController class and set the scroll view as the main view for the controller you are considering.

    Edit

    I created a little sample for you. Here, you have a scroll view as a child of the view of a UIViewController. The scroll view has two views as children: view1 (blue color) and view2 (green color).

    Here, I suppose you can scroll in only one direction: horizontally or vertically. In the following, if you scroll horizontally, you can see that the scroll view works as expected.

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
        scrollView.backgroundColor = [UIColor redColor];
        scrollView.scrollEnabled = YES;
        scrollView.pagingEnabled = YES;
        scrollView.showsVerticalScrollIndicator = YES;
        scrollView.showsHorizontalScrollIndicator = YES;
        scrollView.contentSize = CGSizeMake(self.view.bounds.size.width * 2, self.view.bounds.size.height);    
        [self.view addSubview:scrollView];
    
        float width = 50;
        float height = 50;
        float xPos = 10;
        float yPos = 10;
    
        UIView* view1 = [[UIView alloc] initWithFrame:CGRectMake(xPos, yPos, width, height)];
        view1.backgroundColor = [UIColor blueColor];    
        [scrollView addSubview:view1];
    
        UIView* view2 = [[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width + xPos, yPos, width, height)];
        view2.backgroundColor = [UIColor greenColor];    
        [scrollView addSubview:view2];
    }
    

    If you need to scroll only vertically you can change as follows:

    scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height * 2);
    

    Obviously, you need to rearrange the position of view1 and view2.

    P.S. Here I’m using ARC. If you don’t use ARC, you need to explicitly release alloc-init objects.

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

Sidebar

Related Questions

I have a UIViewController. I want to add a UIToolbar to the bottom, but
I have a UIViewController with a XIB and want to add programmatically another subview.
I am using monotouch and have created a UIViewController. I want to add SegmentControl
I have a UIViewController subclass to control a UIView that I want to add
I have a UIButton in UIViewController, i want add to dynamic number of UITextViews
I have a standard UIViewController which works a charm. However, I want to add
I have a UIViewController that I want to add on top of the entire
I have a UIViewController (which sits inside a tabUIController). Within this UIViewController, I want
I have a custom UIViewController in a UITabbarController and want to respond to rotation
I have a UIView associated with it's own UIViewController that I want to always

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.