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 ...
随机推荐
- SpringAOP进阶
利用代理工厂实现增强 com.Spring.proxyfactory中的IdoSomeService package cn.spring.proxyfactory; public interface ...
- MongoDB 查看chunk块大小
使用mongo shell连到mongos执行命令:AllChunkInfo("dbname.cellname",true) 点击(此处)折叠或打开 AllChunkInfo = ...
- Docker 学习10 Docker的系统资源限制及验证
一.资源限制 二.内存限制 1.OOME 每一个进程都会有oom_adj(oom计算分数的权重)值,此值越大,oom_score(oom得分)越高,越容易被干掉,因此非常非常重要的容器化应用,一开始就 ...
- 007_Python3 字符串
字符串是 Python 中最常用的数据类型.我们可以使用引号( ' 或 " )来创建字符串. 创建字符串很简单,只要为变量分配一个值即可. 例如: var1 = 'Hello World!' ...
- Jquery tabs
官网 http://api.jqueryui.com/tabs/ 必须通过了后台验证tab1的信息后才允许进入tab2 var passed=false; $("#tabs ...
- Mina入门级客户端程序实现telnet程序
Mina入门级客户端程序实现telnet程序,其实mina的客户端和服务端很相似 1.编写客户端MinaClient.java和客户端处理类MyClientHandler.java2.MinaClie ...
- exam9.6&&7
emmm 改题稍紧张,以后几篇并一起写 9.6 (前十并没有参加本次考试) 于是我就rank8了 一道题一道题来 先说T1: 显然是一个高精度GCD,于是打算用计算器算一下时间复杂度 众所周知gcd是 ...
- iptables一些练习
iptables 一些小练习 可以参考之前的一起食用 https://www.cnblogs.com/lovesKey/p/10909633.html 允许来自192.168.0.0/16网段的地址来 ...
- 函数第二部分:为什么说动态参数是没有计划好的参数-Python基础前传(11)
动态参数1-一个星号变元组 动态参数存在的意义? 函数的作者有时候也不知道这个函数到底需要多少个参数,这时候动态参数就有存在的意义了 动态参数创建-加* 底层原理是:把数值型或其他数据类型变成了元组类 ...
- yy
sudo rm -rf /var/cache/apt/archives/python-catkin-pkg-modules_0.4.12-1_all.deb sudo rm -rf /var/cach ...