2016-02-17 64 views

回答

0

添加圖像,滾動型和頁面控制器

UIScrollView *image_scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, 200)]; 
int x=0; 
for (int i=0; i<image_ary.count; i++) 
{ 
    UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(x, 0,screenWidth, height)]; 
    [image_scrollView addSubview:img]; 
    x=screenWidth+x; 
} 
[self.view addSubView image_scrollView]; 
UIPageControl *pageControl = [[UIPageControl alloc] init]; 
pageControl.frame = CGRectMake(screenWidth/4, pageControlY, 160, 30); 
pageControl.numberOfPages = 5; 
pageControl.currentPage = 0; 
[self.view addSubview:pageControl]; 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
float fractionalPage =scrollView.contentOffset.x/screenWidth; 
     NSInteger page = lround(fractionalPage); 
     pageControl.currentPage = page; 
}