本文主要介绍scrollView的使用,使用scrollView来做一个手机相册。
内容不多,直接上代码
#import "RootViewController.h"
#define Kwidth _scrollView.frame.size.width
#define kHight _scrollView.frame.size.height
@interface RootViewController ()
@property(nonatomic,retain)UIScrollView * scrollView;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(30, 100, 320, 480)];
self.view.backgroundColor = [UIColor whiteColor];
_scrollView.backgroundColor = [UIColor greenColor];
[self.view addSubview:_scrollView];
_scrollView.contentSize = CGSizeMake(19*Kwidth,kHight);
for (int i = 0; i<19; i++) {
NSString *imageName = [NSString stringWithFormat:@"image%d.jpg",i+1];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i*Kwidth, 0, Kwidth, kHight)];
imageView.image = image;
[_scrollView addSubview:imageView];
[imageView release];
}
_scrollView.pagingEnabled = YES;
[_scrollView release];
// Do any additional setup after loading the view.
}