zoukankan      html  css  js  c++  java
  • UIScrollView的简单页面

    #import "ViewController.h"

    @interface ViewController ()

    {

        UIImageView *imageview2;

        UIScrollView *sv;

        UIPageControl *page;

    }

    @end

    @implementation ViewController

    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

    {

        CGPoint newOff=scrollView.contentOffset;

        page.currentPage=newOff.x/self.view.frame.size.width+0.5;

     //   [sv addSubview:imageview2];

    }

    - (void)viewDidLoad {

        

        sv=[[UIScrollView alloc]initWithFrame:self.view.frame];

        sv.backgroundColor=[UIColor greenColor];

        sv.pagingEnabled=YES;

        sv.delegate=self;

        

       //UIScrollViewDelegate遵守了这个协议,然后实例化UIScrollview的对象

        NSString *str[]={@"D.jpg",@"oo.jpg",@"ll.jpg",@"u.jpg",@"liu.jpg"};

        page=[[UIPageControl alloc]initWithFrame:CGRectMake(50, self.view.frame.size.height-200, 200, 40)];

        [page addTarget:self action:@selector(changeSV) forControlEvents:UIControlEventValueChanged];

        page.numberOfPages=5;

        page.currentPage=0;

        

        page.currentPageIndicatorTintColor=[UIColor yellowColor];

        page.pageIndicatorTintColor=[UIColor greenColor];

        

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

        {

            UIImage *im=[UIImage imageNamed:[NSString  stringWithString:str[i]]];

            UIImageView *iv=[[UIImageView alloc]initWithImage:im];

            iv.frame=CGRectMake(i*self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);

            if (i==3)

            {

                UITapGestureRecognizer *p=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(go )];

                [iv addGestureRecognizer:p ];

                iv.userInteractionEnabled=YES;

            }

                  [sv addSubview:iv];

        }

         CGSize sz1=CGSizeMake(self.view.frame.size.width*5, self.view.frame.size.height);

        sv.contentSize=sz1;

        [self.view addSubview:sv];

        [self.view addSubview:page];

        [super viewDidLoad];

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

    }

    -(void)changeSV

    {

        sv.contentOffset=CGPointMake(page.currentPage*self.view.frame.size.width, 0);

    }

    -(void)go

    {

      //  [sv removeFromSuperview];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    Pycharm简单使用教程
    【Jenkins学习】【第二节】 jenkins构建触发器定时任务
    Docker之从零开始制作docker镜像
    手机APP自动化环境搭建
    格式字符详解
    Bash Shell之内建命令和保留字
    asp.net 实现后台异步处理的方式
    Spring3.2.0 之后各个版本完整包下载地址
    Oracle的rollup、cube、grouping sets函数
    C# 委托类型及使用
  • 原文地址:https://www.cnblogs.com/linximu/p/4409358.html
Copyright © 2011-2022 走看看