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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:54:08+00:00 2026-06-02T01:54:08+00:00

I am making a simple slideshow view within my app. I’d like to link

  • 0

I am making a simple slideshow view within my app. I’d like to link my UIPageControl to my UIScrollView. This shouldn’t be too difficult, but I haven’t been able to find a simple solution anywhere. Below is my code.

HelpViewController.h

#import <UIKit/UIKit.h>

@interface HelpViewController : UIViewController{
}
@end

HelpViewController.m

#import "HelpViewController.h"

@interface HelpViewController ()

@end

@implementation HelpViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    CGRect scrollViewFrame = CGRectMake(0, 62, 320, 404);
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
    [self.view addSubview:scrollView];
    CGSize scrollViewContentSize = CGSizeMake(640, 404);
    [scrollView setContentSize:scrollViewContentSize];
    UILabel *label  = [[UILabel alloc] initWithFrame:CGRectMake(200, 200, 50, 21)];
    [label setText:@"Hello"];
    [scrollView addSubview:label];
    [scrollView setPagingEnabled:YES];
    scrollView.showsHorizontalScrollIndicator = NO;
    UIPageControl *pageControl = [[UIPageControl alloc] init]; 
    pageControl.frame = CGRectMake(110,5,100,100); 
    pageControl.numberOfPages = 2; 
    pageControl.currentPage = 0; 
    [self.view addSubview:pageControl];
    pageControl.backgroundColor = [UIColor redColor];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
  • 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-02T01:54:10+00:00Added an answer on June 2, 2026 at 1:54 am

    Maybe this works for you

    Don’t forget to set the UIScrollView’s delegate = self (or wherever you have the selector below).

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        CGFloat pageWidth = self.scrollView.frame.size.width; // you need to have a **iVar** with getter for scrollView
        float fractionalPage = self.scrollView.contentOffset.x / pageWidth;
        NSInteger page = lround(fractionalPage);
        self.pageControl.currentPage = page; // you need to have a **iVar** with getter for pageControl
    }
    

    For your code it then would be:

    .h file

    #import <UIKit/UIKit.h>
    
    @interface HelpViewController : UIViewController{
    }
    
    @property (nonatomic, retain) UIScrollView *scrollView;
    @property (nonatomic, retain) UIPageControl * pageControl;
    @end
    

    .m file

    #import "HelpViewController.h"
    
    @interface HelpViewController ()
    
    @end
    
    @implementation HelpViewController
    @synthesize scrollView=scrollView_;
    @synthesize pageControl=pageControl_;
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        CGRect scrollViewFrame = CGRectMake(0, 62, 320, 404);
        self.scrollView = [[[UIScrollView alloc] initWithFrame:scrollViewFrame] autorelease];
        self.scrollView.delegate = self;
        [self.view addSubview:self.scrollView];
        CGSize scrollViewContentSize = CGSizeMake(640, 404);
        [self.scrollView setContentSize:scrollViewContentSize];
        UILabel *label  = [[UILabel alloc] initWithFrame:CGRectMake(200, 200, 50, 21)];
        [label setText:@"Hello"];
        [self.scrollView addSubview:label];
        [self.scrollView setPagingEnabled:YES];
        self.scrollView.showsHorizontalScrollIndicator = NO;
        self.pageControl = [[[UIPageControl alloc] init] autorelease]; 
        self.pageControl.frame = CGRectMake(110,5,100,100); 
        self.pageControl.numberOfPages = 2; 
        self.pageControl.currentPage = 0; 
        [self.view addSubview:self.pageControl];
        pageControl.backgroundColor = [UIColor redColor];
    }
    
    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
     - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
            CGFloat pageWidth = self.scrollView.frame.size.width;
            float fractionalPage = self.scrollView.contentOffset.x / pageWidth;
            NSInteger page = lround(fractionalPage);
            self.pageControl.currentPage = page; 
        }
    
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple app than needs to store a simple structure of data.
I am making simple graphical game in WinForms and currently I would like to
How to change sizes of ViewController? I'm making simple app which uses deliberately two
Im making a simple proof of concept page with jQuery: $('.notclicked').click(function() { $(this).addClass(clicked); $(this).removeClass(notclicked);
Im making a simple app for some friends to use on there android phone
I am making a simple web browser in Scala 2.9. This is only using
Making a simple map app, plan on adding buttons to mark specific locations But
Iam making a simple app, I display pdf file with some text and images
I'm making a simple reading canvas app, and I want to be ale to
I am making simple connection between two table - first one called users has

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.