nikesh
nikesh

Reputation: 140

page control images with scroll

I have to invoke images in the given code instead of the colour, i have four images to invoke here can any one tell me how do i invoke the images in the given code ...

.h file

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIScrollViewDelegate>

@end

.m file

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

    NSInteger numberOfViews = 3;

    for (int i = 0; i < numberOfViews; i++) 
    {
        CGFloat xOrigin = i * self.view.frame.size.width;

        UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];

        awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];

        [scroll addSubview:awesomeView];

        [awesomeView release];

    }

    scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);

   //  scroll.pagingEnabled = YES;

    scroll.pagingEnabled = YES;

  //  scroll.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);

    scroll.showsHorizontalScrollIndicator = NO;

    scroll.showsVerticalScrollIndicator = NO;

    scroll.scrollsToTop = NO;

    //  self.pageControl.currentPage = 1;

    [self.view addSubview:scroll];

    [scroll release];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.
}

@end

now i need to have the page control with images using coding and not xib.

Upvotes: 0

Views: 236

Answers (1)

ask4asif
ask4asif

Reputation: 676

You can add page control programmatically as

CGRect frame = //desired frame;
_pageControl = [[[PageControl alloc] initWithFrame:frame] autorelease];
_pageControl.numberOfPages = numberOfViews;
_pageControl.delegate = self;
[self.view addSubview:_pageControl];
[self.view bringSubviewToFront:_pageControl];

Upvotes: 1

Related Questions