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 ...
随机推荐
- Apicloud 之按两次后退键退出应用
api.addEventListener({ name: 'keyback' }, function(ret, err) { if (flag == 1) { api.closeWidget({ si ...
- mongodb中帮助信息和命令
在Mongodb中,可以看作是一种面向对象的操作,如果你对与某一个操作不清楚,可以直接help. 在mongodb中,无非是对DB.user.collections.文档的操作. 下面是简单的示例: ...
- Jquery tabs
官网 http://api.jqueryui.com/tabs/ 必须通过了后台验证tab1的信息后才允许进入tab2 var passed=false; $("#tabs ...
- 51nod 3 * problem
1640题意:一张无向图在最小化最大边后求最大边权和 Slove:sort 最小生成树倒叙最大生成树 #include <iostream> #include <cstdio> ...
- TensorFlow(一):准备
我的环境:win10+python3.6.4(64位) 一:安装python 根据自己的电脑下载python(32位或者64位)-->安装教程 安装好python后记得配置pip源,使用官方的源 ...
- NetworkX系列教程(3)-手动创建graph
小书匠Graph图论 不可否认,日常中我们使用最多的还是,使用自己的数据去手动创建自己的图形,而不是使用生成器,现从给graph添加点和边入手,讲解手动创建graph. 目录: 3.给graph添加节 ...
- kaptcha 配置
问题所在: 这一段配置,不要写在 SpringMVC 文件中,要写在 Spring 配置文件! <!-- kaptcha 验证码 --> <bean id="captcha ...
- 跑shell脚本出错问题以及解决。
脚本信息: #!/bin/bash function hello(){ cat <<YJT echo "hello world!!!" YJT } hello 错误: ...
- java关于Integer设置-128到127的静态缓存
今天在一个java群里,看到有个群友问到如下为什么第一个为true,第二个为false. System.out.println(Integer.valueOf("50")==Int ...
- vue实现element-ui对话框可拖拽功能
element-ui对话框可拖拽及边界处理 应业务需求,需要实现对话框可拖拽问题,应element-ui没有提供官方支持,于是便参考大神的文章,得出了适合业务需要的解决方案.很多大神给出的代码是没有解 ...