zoukankan      html  css  js  c++  java
  • 图片循环

    @interface ViewController ()<UIScrollViewDelegate>

    {

        NSInteger page;

    }

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad

    {

        [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

        

        UIScrollView *sv=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];

        sv.backgroundColor=[UIColor cyanColor];

        sv.contentSize=CGSizeMake(320*6, 568);

        [self.view addSubview:sv];

        

        for (int i=0; i<6; i++)

        {

            if (i==0) {

                UIImageView *iv=[[UIImageView alloc]initWithFrame:CGRectMake(320*i, 0, 320, 568)];

                iv.image=[UIImage imageNamed:[NSString stringWithFormat:@"2_4.jpg"]];

                [sv addSubview:iv];

                iv.userInteractionEnabled=YES;

            }else if (i==5)

            {

                UIImageView *iv=[[UIImageView alloc]initWithFrame:CGRectMake(320*i, 0, 320, 568)];

                iv.image=[UIImage imageNamed:[NSString stringWithFormat:@"2_1.jpg"]];

                [sv addSubview:iv];

            }else {

            UIImageView *iv=[[UIImageView alloc]initWithFrame:CGRectMake(320*i, 0, 320, 568)];

            iv.image=[UIImage imageNamed:[NSString stringWithFormat:@"2_%d.jpg",i]];

            [sv addSubview:iv];

            }

        }

        sv.pagingEnabled=YES;

        sv.delegate=self;

    }

     

    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

    {

        page=scrollView.contentOffset.x/320;

        if (!page) {

            [scrollView setContentOffset:CGPointMake(320*4, 0)];

        }

        if (page==5) {

            [scrollView setContentOffset:CGPointMake(320, 0)];

        }

    }

     

    让明天,不后悔今天的所作所为
  • 相关阅读:
    20162329张旭升 2017-2018-2 《程序设计与数据结构》第一周学习总结
    20162329 张旭升2016-2017《程序设计与数据结构》课程总结
    实验报告五
    20162329 张旭升 阶段四则运算(挑战出题)
    实验四:Android 开发基础
    四则运算的整体总结(第二周)
    结对编程四则运算(阶段总结)
    团队项目-选题报告
    第二次结对编程作业
    第一次结对编程作业
  • 原文地址:https://www.cnblogs.com/-yun/p/4379159.html
Copyright © 2011-2022 走看看