scollView和pageControlView
来源:互联网 发布:php调用网页代码 编辑:程序博客网 时间:2024/06/16 20:51
#import "RootViewController.h"#import "RootView.h"@interface RootViewController () <UIScrollViewDelegate>#pragma mark - 声明私有属性@property (nonatomic, retain) RootView *rootView;@end@implementation RootViewController#pragma mark - 设置自定义视图- (void)loadView{ self.rootView = [[[RootView alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease]; self.view = _rootView;}- (void)viewDidLoad{ [super viewDidLoad]; // 设置滚动视图代理 _rootView.scrollView.delegate = self; // 给小点点绑定事件 [_rootView.pageControl addTarget:self action:@selector(pageControlAction:) forControlEvents:UIControlEventValueChanged];}#pragma mark - 小点点的事件- (void)pageControlAction:(UIPageControl *)sender{ CGPoint offset = CGPointMake(0, sender.currentPage * _rootView.scrollView.frame.size.height);// _rootView.scrollView.contentOffset = offset; [_rootView.scrollView setContentOffset:offset animated:YES];}#pragma mark - 停止滚动- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ NSInteger index = scrollView.contentOffset.y / scrollView.frame.size.height; _rootView.pageControl.currentPage = index; }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark - 重写#pragma mark dealloc- (void)dealloc{ [_rootView release]; [super dealloc];}
#import "RootView.h"@implementation RootView- (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor cyanColor]; [self addAllViews]; } return self;}#pragma mark - 添加全部控件- (void)addAllViews{ // 1.添加滚动视图 self.scrollView = [[[UIScrollView alloc] initWithFrame:self.frame] autorelease]; [self addSubview:_scrollView]; // 2.添加小点点 self.pageControl = [[[UIPageControl alloc] initWithFrame:CGRectMake(10, self.frame.size.height - 30, self.frame.size.width - 20, 20)] autorelease]; _pageControl.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5f]; [self addSubview:_pageControl]; // 添加图片到scrollView NSInteger count = 9; for (int i = 0; i < count; i++) { NSString *imgName = [NSString stringWithFormat:@"bg_%d.JPG", i]; UIImage *image = [UIImage imageNamed:imgName]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.frame = CGRectMake(0, i * _scrollView.frame.size.height, _scrollView.frame.size.width, _scrollView.frame.size.height); [_scrollView addSubview:imageView]; [imageView release]; } _scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width, _scrollView.frame.size.height * count); _scrollView.pagingEnabled = YES; _scrollView.showsVerticalScrollIndicator = NO; _scrollView.showsHorizontalScrollIndicator = NO; // 小点点个数 _pageControl.numberOfPages = count;}#pragma mark - 重写#pragma mark dealloc- (void)dealloc{ [_scrollView release]; [_pageControl release]; [super dealloc];}
0 0
- scollView和pageControlView
- ScollView和ListView 发生冲突解决方案
- 解决Scollview和ListView冲突的问题
- android 中ScollView和ListView的使用
- Android学习之ScollView嵌套ListView和GridView问题
- 解决Android学习之ScollView嵌套ListView和GridView问题
- Android自定义GridView——解决和ScollView的滑动冲突问题
- scollView中实现缩放
- 有弹性的scollview
- scollview 冲突gridview
- scollview嵌套grideview
- android 弹性scollview 多功能
- scollview条目连动
- scollview滑动底部
- 关于scollview嵌套recyclerview
- ReactNative ScollView 组件
- listview、scollview、webview的下拉刷新,上拉加载。效果特别好,带刷新时间和图片
- 容器类视图之scollview
- Citrix VDI 跨平台桌面虚拟化架构的研究
- VS2010与SQL Server2008链接使用混合登陆方式
- 第八章:exception&游标&rowtype&集合/数组
- js键盘事件全面控制 兼容FireFox和IE
- ios des加密
- scollView和pageControlView
- 状态栏(statusBar)下拉操作
- 更新证书错误:No matching provisioning profiles found
- 万年历
- c语言称重砝码
- 字典树模板(动态)
- 第九章:记录&触发器&存储过程
- UML 是什么?常用的几种图?
- java可变参数