我必须调用给定代码中的图像而不是颜色,我有四个要调用的图像,任何人都可以告诉我如何调用给定代码中的图像......
.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来控制带有图像的页面。
答案 0 :(得分: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];