zoukankan      html  css  js  c++  java
  • 滚动视图部分代码

    - (void)viewDidLoad {
        [super viewDidLoad];
        self.myscrollV=[[UIScrollView alloc]init];
        self.myscrollV.frame=CGRectMake(0, 0, WIDTH,HEIGHT);
        self.myscrollV.contentSize=CGSizeMake(WIDTH*4,HEIGHT);
        self.myscrollV.backgroundColor=[UIColor grayColor];
       
       
        self.imageVC1=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
        self.imageVC1.image=[UIImage imageNamed:@"100.jpg"];
        [self.myscrollV addSubview:self.imageVC1];
       
        self.imageVC2=[[UIImageView alloc] initWithFrame:CGRectMake(WIDTH, 0, WIDTH, HEIGHT)];
        self.imageVC2.image=[UIImage imageNamed:@"101.jpg"];
        [self.myscrollV addSubview:self.imageVC2];
       
        self.imageVC3=[[UIImageView alloc] initWithFrame:CGRectMake(WIDTH*2, 0, WIDTH, HEIGHT)];
        self.imageVC3.image=[UIImage imageNamed:@"102.jpg"];
        [self.myscrollV addSubview:self.imageVC3];
       
        self.imageVC4=[[UIImageView alloc] initWithFrame:CGRectMake(WIDTH*3, 0, WIDTH, HEIGHT)];
        self.imageVC4.image=[UIImage imageNamed:@"103.jpg"];
        [self.myscrollV addSubview:self.imageVC4];
       
        //锁定滑动方向
        self.myscrollV.directionalLockEnabled=NO;
        //设置分页
        self.myscrollV.pagingEnabled=YES;
        //设定是否回弹
        self.myscrollV.bounces=NO;
        [self.view addSubview:self.myscrollV];

        self.button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
        [self.button setTitle:@"立即体验" forState:UIControlStateNormal];
        self.button.frame=CGRectMake(WIDTH*4-200, self.view.frame.size.height-100, 100, 50);
        self.button.backgroundColor=[UIColor greenColor];
        [self.button addTarget:self action:@selector(changeCount) forControlEvents:UIControlEventTouchDown];
        self.myscrollV.delegate=self;
        [self.myscrollV addSubview:self.button];
       
       
        self.page=[[UIPageControl alloc]init];
        CGSize pageSize=CGSizeMake(150, 44);
        self.page.frame=CGRectMake((WIDTH-pageSize.width)/0.5, HEIGHT-pageSize.height-40, pageSize.width, pageSize.height);
        self.page.backgroundColor=[UIColor whiteColor];
        self.page.numberOfPages=4;
        self.page.currentPage=0;
       
       
       
    }
    -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
        //设置分页
       
        self.page.currentPage=(int)(scrollView.contentOffset.x/WIDTH);
    }

    -(void)changPage
    {
       
    //    ViewController *viewC=[[ViewController alloc]init];
        [self presentViewController:[ViewController new] animated:YES completion:^{
            NSLog(@"进入主页");
        }];
       
    }
  • 相关阅读:
    -_-#【MongoDB】日期类型
    -_-#【Better Code】字符串匹配
    -_-#【Canvas】圆弧运动
    -_-#【Canvas】
    -_-#【AngularJS】
    COGS——C 14. [网络流24题] 搭配飞行员
    CODEVS——T 1993 草地排水 USACO
    BZOJ——T2190: [SDOI2008]仪仗队
    Codeforces_GYM_100741 A
    2017-0722 模拟赛
  • 原文地址:https://www.cnblogs.com/wrzheng/p/5346049.html
Copyright © 2011-2022 走看看