iOS UIPageControl与UIScrollView配合使用代码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了iOS UIPageControl与UIScrollView配合使用代码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3381字,纯文字阅读大概需要5分钟。
内容图文
#import "RootViewController.h" #import "RootView.h" @interface RootViewController ()<UIScrollViewDelegate> @property(nonatomic,retain)RootView *myview; @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization self.myview = [[RootView alloc] initWithFrame:[UIScreen mainScreen].bounds]; [self.myview.page addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged]; } return self; } -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { self.myview.page.currentPage = scrollView.contentOffset.x / [UIScreen mainScreen].bounds.size.width; } -(void)pageAction:(UIPageControl*)sender { [UIView animateWithDuration:0.5 animations:^{ self.myview.scrollV.contentOffset = CGPointMake(sender.currentPage*[UIScreen mainScreen].bounds.size.width, 0); }]; } -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.myview.imV; } -(void)loadView { self.view = self.myview; self.myview.scrollV.delegate = self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end
#import <UIKit/UIKit.h> @interface RootView : UIView @property(nonatomic,retain)UIScrollView *scrollV; @property(nonatomic,retain)UIImageView *imV; @property(nonatomic,retain)UIPageControl *page; @end
#import "RootView.h" @implementation RootView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self addAllViews]; } return self; } -(void)addAllViews { self.scrollV = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.scrollV.backgroundColor = [UIColor yellowColor]; self.scrollV.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width*8, 0); self.scrollV.pagingEnabled = YES; // self.scrollV.bounces = NO; // self.scrollV.bouncesZoom = NO; self.scrollV.minimumZoomScale = 0.3; self.scrollV.maximumZoomScale = 2; self.scrollV.zoomScale = 0.3; [self addSubview:self.scrollV]; for (int i = 0; i < 9; i++) { self.imV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"h%d.jpeg",i+1]]]; self.imV.frame = CGRectMake([UIScreen mainScreen].bounds.size.width*i, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); [self.scrollV addSubview:self.imV]; } self.page = [[UIPageControl alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-30, [UIScreen mainScreen].bounds.size.width, 30)]; self.page.backgroundColor = [UIColor grayColor]; self.page.numberOfPages = 8; self.page.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0]; self.page.pageIndicatorTintColor = [UIColor grayColor]; [self addSubview:self.page]; }
原文:http://blog.csdn.net/shichangbu123/article/details/40794691
内容总结
以上是互联网集市为您收集整理的iOS UIPageControl与UIScrollView配合使用代码全部内容,希望文章能够帮你解决iOS UIPageControl与UIScrollView配合使用代码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。