// // bookshiefViewController.m // bookshief // // Created by JON MOODY on 12/15/11. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import "bookshiefViewController.h" @implementation bookshiefViewController - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; float t_width=320; int t_bookshelf=20; int t_bookshelf_height=120; [m_UIScrollView setContentSize:CGSizeMake(t_width, t_bookshelf_height*t_bookshelf)]; for(int i=0;i<t_bookshelf;i++){ [self fun_viewDidLoad_Addbooks:(double)t_width i_height:(double)t_bookshelf_height*i]; } } -(void)fun_viewDidLoad_Addbooks:(double)t_width i_height:(double)i_height{ int t_books=20; float t_height=100; int t_width2=t_height; //每一書的寬度 int t_board_wdith=20; //書與書的間隔 UIScrollView* m_UIScrollView1=[[UIScrollView alloc] initWithFrame:CGRectMake(0,i_height,t_width,t_height) ] ; [m_UIScrollView1 setContentSize:CGSizeMake(t_books*(t_width2+t_board_wdith),t_height)]; [m_UIScrollView addSubview:m_UIScrollView1]; // 加上圖片 for(int i=0;i<t_books;i++){ UIImageView *contentView2 = [[UIImageView alloc] initWithFrame:CGRectMake(i*(t_width2+t_board_wdith),0,t_width2,t_height)]; [contentView2 setImage:[UIImage imageNamed:@"Default.png"]]; [m_UIScrollView1 addSubview:contentView2]; } } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end
sample code: book shelf