iOS-UIScrollView+UIPageControl简单实现
#import "MJViewController.h"
#import "RootViewController.h"
@interface MJViewController () <UIScrollViewDelegate>
@property (strong, nonatomic) UIScrollView *scrollView;
@property (strong, nonatomic) UIPageControl *pageControl;
@property (strong, nonatomic) UIButton *nextBt;
@end
@implementation MJViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//初始化视图
NSArray *array = [NSArray arrayWithObjects:[UIColor redColor],[UIColor blueColor],[UIColor yellowColor],[UIColor purpleColor],[UIColor whiteColor], nil];
self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(10, 80, self.view.frame.size.width-20, self.view.frame.size.height-100)];
self.scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor];
self.automaticallyAdjustsScrollViewInsets = NO;//恢复scrollview偏移
self.scrollView.delegate = self;
self.scrollView.pagingEnabled = YES; //分页属性
self.scrollView.showsHorizontalScrollIndicator= NO;
self.scrollView.showsVerticalScrollIndicator = NO;
self.scrollView.contentSize = CGSizeMake((self.view.frame.size.width-20)*[array count], self.scrollView.frame.size.height); //内容范围
[self.view addSubview:self.scrollView];
self.pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(10,self.view.frame.size.height-50, self.view.frame.size.width-20, 20)];
// self.pageControl.backgroundColor = [UIColor grayColor];
self.pageControl.numberOfPages = array.count;
self.pageControl.currentPage = 0;
[self.view addSubview:self.pageControl];
for (int i = 0; i<array.count; i++) {
UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(i*self.scrollView.frame.size.width+5, 5, self.scrollView.frame.size.width-10, self.scrollView.frame.size.height-10)];
imageview.backgroundColor = array[i];
[self.scrollView addSubview:imageview];
if (i==array.count-1) {
imageview.userInteractionEnabled = YES;
self.nextBt = [[UIButton alloc]initWithFrame:CGRectMake(0,0,200, 44)];
_nextBt.alpha = 0.5;
_nextBt.backgroundColor = [UIColor darkGrayColor];
[_nextBt setTitle:@"开启致富之旅" forState:UIControlStateNormal];
[_nextBt setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[_nextBt addTarget:self action:@selector(gotoAction) forControlEvents:UIControlEventTouchUpInside];
[imageview addSubview:self.nextBt];
}
}
}
-(void)gotoAction{
RootViewController *rootVC = [[RootViewController alloc]init];
[self presentModalViewController:rootVC animated:YES];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if ([scrollView isMemberOfClass:[UITableView class]]) {
}else{
//在scrollViewDidScroll内实现监听contentOffset内容偏移量;根据contentOffset计算当前属于哪一页;
int index = fabs(scrollView.contentOffset.x)/scrollView.frame.size.width;//当前是第几个视图
self.pageControl.currentPage = index;
}
}
然后在代理里面记得实现:
#pragma mark - 引导页
- (void)setIntroductionViewController
{
//读取沙盒数据
NSUserDefaults * settings1 = [NSUserDefaults standardUserDefaults];
NSString *key1 = [NSString stringWithFormat:@"is_first"];
NSString *value = [settings1 objectForKey:key1];
if (!value) {//如果没有数据
//***
//引导页
introductionVC = [[DMIntroductionViewController alloc]init];
[UIApplication sharedApplication].delegate.window.rootViewController = introductionVC;
}
}
@end
iOS-UIScrollView+UIPageControl简单实现的更多相关文章
- 启动图实现:UIScrollView+UIPageControl简单实现
#import "MJViewController.h"#import "RootViewController.h" @interface MJViewCont ...
- iOS UIScrollView的简单使用
本文代码下载 http://vdisk.weibo.com/s/BDn59yfnBVMAJ // // ViewController.m // ScrollView_T1119 // // Creat ...
- ios下最简单的正则,RegexKitLite
ios下最简单的正则,RegexKitLite 1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中.备用地址:http://www.coco ...
- iOS中XMPP简单聊天实现 好友和聊天
版权声明本文由陈怀哲首发自简书:http://www.jianshu.com/users/9f2e536b78fd/latest_articles;微信公众号:陈怀哲(chenhuaizhe2016) ...
- IOS UIScrollView常用代理方法
iOS UIScrollView代理方法有很多,从头文件中找出来学习一下 //只要滚动了就会触发 - (void)scrollViewDidScroll:(UIScrollView *)scrollV ...
- iOS百度地图简单使用详解
iOS百度地图简单使用详解 百度地图 iOS SDK是一套基于iOS 5.0及以上版本设备的应用程序接口,不仅提供展示地图的基本接口,还提供POI检索.路径规划.地图标注.离线地图.定位.周边雷达等丰 ...
- iOS设计模式 - (3)简单工厂模式
iOS设计模式 - (3)简单工厂模式 by Colin丶 转载请注明出处: http://blog.csdn.net/hitwhylz/article/ ...
- iOS纯代码制作欢迎界面——UIScrollView, UIPageControl, UIImageView,UIButton, NSTimer
欢迎界面,还是比较简单的,一个UIScrollView控件,一个UIPageControl,几个UIImageView即可摆平.在这里光玩这些,就显得诚意不足了.特意拓展一下,再加几个UIButton ...
- iOS— UIScrollView和 UIPageControl之间的那些事
本代码主要实现在固定的位置滑动图片可以切换. 目录图如下: ViewController.h #import <UIKit/UIKit.h> // 通过宏定义定义宽和高 #define W ...
- IOS初级:UIScrollView & UIPageControl
UIScrollView其实构建的就像一列很长的火车,每滑动一个屏幕,展示一节车厢. //主屏幕高度 #define kScreenHeight [UIScreen mainScreen].bound ...
随机推荐
- 找到一些经验,关于使用thymeleaf时遇到的一些问题
最近一直在使用spring boot,所以自然而然的使用了thymeleaf,但是我想说习惯了jsp之后使用thymeleaf真实觉得不顺手,在使用thymeleaf中也遇到了一些问题,在这里记录一下 ...
- React重置非受控组件state的方法
如果想通过props来重置state的值.有3种方法: 1. 最好的方法:key属性 修改key属性的值,可以使组件卸载后重新加载.所有的状态全部重置. 这种情况可以给key设一个每次渲染都会改变的值 ...
- xml介绍+xml创建+xml读取
1.xml介绍:(URL:https://blog.csdn.net/weixin_37861326/article/details/81082144) xml是用来传输内容的,是w3c推荐的 2.使 ...
- loj #2319
noip2017列队 - resolve 标签:题解 \(n * m\) 的矩阵,每个元素 \((i, j)\) 的标号为 \((i - 1) * m + j\), 每次给出 \((x, y)\), ...
- 【概率论】5-3:超几何分布(The Hypergeomtric Distribution)
title: [概率论]5-3:超几何分布(The Hypergeomtric Distribution) categories: - Mathematic - Probability keyword ...
- YII框架入门
一.安装 php运行环境安装包:http://www.phpstudy.net/a.php/207.html Yii安装包: https://github.com/yiisoft/yii2/relea ...
- redis基准性能测试
1 测试目的 了解redis在不同情况下的性能表现,并分析其性能瓶颈,找出相应的解决方案. 2 redis基准测试概览 运行下列命令可以了解自己的redis服务器的基本性能指标. 通过loopback ...
- 网DAI之家简单爬取
用requests和bs做个简单的爬取网DAI之家的例子. 只做笔记用. #!/usr/bin/python3 import requestsfrom bs4 import BeautifulSoup ...
- 网络爬虫requests-bs4-re-1
最近了解了爬虫,嗯--------,有时候会搞得有点头晕. 跟着线上老师实现了两个实例.可以用python下载源代码玩玩,爬淘宝的很刺激,虽然违反了ROBOTS协议. GIT地址
- HBase-集群安装
需要先启动 HDFS 集群和 ZooKeeper 集群. Hadoop 集群安装:https://www.cnblogs.com/jhxxb/p/10629796.html ZooKeeper 集群安 ...