标签:style io ar for sp strong on cti ad
ViewController.h
@interface ViewController : UIViewController<UIScrollViewDelegate> { UIPageControl *_pageCtrl; UIScrollView *_scrollView; }
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // NSMutableArray *imgArrary = [[NSMutableArray alloc] init]; //创建滚动视图 _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 300)]; //隐藏滚动条 _scrollView.showsHorizontalScrollIndicator = NO; //设置代理方法 _scrollView.delegate = self; //分页效果 _scrollView.pagingEnabled = YES; //设置内容尺寸 _scrollView.contentSize = CGSizeMake(320*5, 300); [self.view addSubview:_scrollView]; for(int i=1; i<6; i++) { NSString *name = [NSString stringWithFormat:@"image%d.jpg",i]; UIImage *image = [UIImage imageNamed:name]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.frame = CGRectMake(320*(i-1), 0, 320, 300); [_scrollView addSubview:imageView]; } //创建分页控键 _pageCtrl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 300, 320, 20)]; _pageCtrl.numberOfPages = 5; _pageCtrl.currentPage = 0; [_pageCtrl addTarget:self action:@selector(pageAction) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:_pageCtrl]; } #pragma mark - UIScrollView delegate //- (void)scrollViewDidScroll:(UIScrollView *)scrollView { // // /* // 0: 0--320 /320 0 // 1; 320--640 /320 1 // */ // // int count = scrollView.contentOffset.x/320; // _pageCtrl.currentPage = count; // //} //视图停止以后调用 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { int count = scrollView.contentOffset.x/320; _pageCtrl.currentPage = count; } - (void)pageAction { int index = _pageCtrl.currentPage; CGPoint point = CGPointMake(320*index, 0); // _scrollView.contentOffset = point; [_scrollView setContentOffset:point animated:YES]; } @end
标签:style io ar for sp strong on cti ad
原文地址:http://blog.csdn.net/pengyuan_d/article/details/40682363