UIScrollView多张图分页

//创建UIScrollView

    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:self.view.bounds];

    

    for (NSInteger i=1; i<=5; i++) {

        

        NSString *imageFile=[NSString stringWithFormat:@"%ld.jpg",(long)i];

        

        UIImage *image=[UIImage imageNamed:imageFile];

        

        UIImageView *imageView=[[UIImageView alloc] initWithImage:image];

        

        [imageView setFrame:CGRectMake((i-1)*scrollView.bounds.size.width, 0, scrollView.bounds.size.width, scrollView.bounds.size.height)];

        

        [scrollView addSubview:imageView];

        

    }

    //关闭弹性

    [scrollView setBounces:NO];

    //关闭水平滚动条

    [scrollView setShowsHorizontalScrollIndicator:YES];

    //设置内容大小

    [scrollView setContentSize:CGSizeMake(scrollView.bounds.size.width*5, scrollView.bounds.size.height)];

    

    [self.view addSubview:scrollView];

posted on 2015-11-12 23:07  jayhtt  阅读(77)  评论(0)    收藏  举报