//建立滾動視圖 scroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; scroll.pagingEnabled=YES;//設定翻頁效果 scroll.showsHorizontalScrollIndicator=NO;//不顯示水平捲軸 scroll.delegate=self; scroll.contentSize=CGSizeMake(320*NUM, 460);//內容大小 for (int i=0; i<NUM; i++) { UIImageView * imgView=[[UIImageView alloc] initWithFrame:CGRectMake(i*320, 0, 320, 460)]; UIImage * img=[UIImage imageNamed:@"IMG_0012.JPG"]; imgView.image=img; [scroll addSubview:imgView]; [imgView release]; } [self.view addSubview:scroll]; [scroll release];--------------------------------------------------------- //建立分頁檢視 page=[[UIPageControl alloc] initWithFrame:CGRectMake(0, 350, 320, 60)]; page.numberOfPages=NUM;//頁碼數 page.pageIndicatorTintColor=[UIColorblackColor];//非當前頁的點顏色 page.currentPageIndicatorTintColor=[UIColorblueColor];//當前頁的點顏色 [pageaddTarget:selfaction:@selector(pageEventAction:) forControlEvents:UIControlEventValueChanged];//添加事件處理 [self.view addSubview:page]; [page release];-----------------------------------------------------------//滾動視圖跟分頁控制器關聯-(void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ CGPoint p=scrollView.contentOffset;//位移量 int n=p.x/320; page.currentPage=n;//當前頁碼}//點擊分頁檢視觸發事件-(void) pageEventAction:(UIPageControl *) sender{ scroll.contentOffset=CGPointMake(sender.currentPage*320, 0);}