0

我必须调用给定代码中的图像而不是颜色,我有四个图像要在这里调用,谁能告诉我如何调用给定代码中的图像...

.h 文件

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIScrollViewDelegate>

@end

.m 文件

#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

现在我需要使用编码而不是 xib 来使用带有图像的页面控件。

4

1 回答 1

1

您可以以编程方式添加页面控件

CGRect frame = //desired frame;
_pageControl = [[[PageControl alloc] initWithFrame:frame] autorelease];
_pageControl.numberOfPages = numberOfViews;
_pageControl.delegate = self;
[self.view addSubview:_pageControl];
[self.view bringSubviewToFront:_pageControl];
于 2012-12-19T11:28:46.597 回答