码迷,mamicode.com
首页 > 其他好文 > 详细

UIScrollView的简单页面

时间:2015-04-09 13:27:47      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

#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

 

UIScrollView的简单页面

标签:

原文地址:http://www.cnblogs.com/linximu/p/4409358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!