iOS UIPageControl与UIScrollView配合使用代码
2014-11-04 21:56
330 查看
#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]; }
相关文章推荐
- iosUIScrollView以及UIPageControl的基本使用以及所有代理方法
- [iOS] UIScrollView与软键盘配合心得——点击空白处隐藏软键盘(完美方案,不增代码)
- iOS UIScrollView、UIPageControl、NSTimer的使用
- UIScrollView和UIPageControl的配合使用 - iOS - UI基础知识总结11
- IOS--UIScrollView和UIPageControl配合使用
- ios-day05-04(图片轮播器 UIScrollView的分页、UIPageControl的使用、NSTimer(定时器)的使用)
- iOS UIScrollView 和 UIPageControl的简单使用
- iOS 工作笔记之PKRevealController和UIScrollView,UITableView的配合使用
- iOS纯代码制作欢迎界面——UIScrollView, UIPageControl, UIImageView,UIButton, NSTimer
- iOS学习之UIScrollView及UIPageControl的使用
- iOS--UIScrollView和UIPageControl配合使用完成引用介绍页面
- IOS UIScrollView与UIPageController配合使用
- iPhone开发之UIScrollView滚动组件的使用(七)利用NSTimer计时器和UIPageControl组件代码实现图片轮播器
- iOS开发-UI (十)UIScrollView 和 UIPageControl使用
- iOS开发 自定义tableView样式(使用代码/使用Interface Builder)、分组显示、给TableView增加索引、给TableView增加SearchBariOS开发 自定义tab
- [IOS]使用UIScrollView和UIPageControl显示半透明帮助蒙板
- iOS使用UIScrollView实现左右滑动UITableView和UICollectionView
- [iOS]UIScrollView 与 UIPageControl实现简单相册功能
- IOS开发~UISCrollView与UITableView嵌套使用终极解决方案
- [转]IOS 学习笔记(8) 滚动视图(UIScrollView)的使用方法