#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简单实现的更多相关文章

  1. 启动图实现:UIScrollView+UIPageControl简单实现

    #import "MJViewController.h"#import "RootViewController.h" @interface MJViewCont ...

  2. iOS UIScrollView的简单使用

    本文代码下载 http://vdisk.weibo.com/s/BDn59yfnBVMAJ // // ViewController.m // ScrollView_T1119 // // Creat ...

  3. ios下最简单的正则,RegexKitLite

    ios下最简单的正则,RegexKitLite 1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中.备用地址:http://www.coco ...

  4. iOS中XMPP简单聊天实现 好友和聊天

    版权声明本文由陈怀哲首发自简书:http://www.jianshu.com/users/9f2e536b78fd/latest_articles;微信公众号:陈怀哲(chenhuaizhe2016) ...

  5. IOS UIScrollView常用代理方法

    iOS UIScrollView代理方法有很多,从头文件中找出来学习一下 //只要滚动了就会触发 - (void)scrollViewDidScroll:(UIScrollView *)scrollV ...

  6. iOS百度地图简单使用详解

    iOS百度地图简单使用详解 百度地图 iOS SDK是一套基于iOS 5.0及以上版本设备的应用程序接口,不仅提供展示地图的基本接口,还提供POI检索.路径规划.地图标注.离线地图.定位.周边雷达等丰 ...

  7. iOS设计模式 - (3)简单工厂模式

    iOS设计模式 - (3)简单工厂模式           by Colin丶 转载请注明出处:              http://blog.csdn.net/hitwhylz/article/ ...

  8. iOS纯代码制作欢迎界面——UIScrollView, UIPageControl, UIImageView,UIButton, NSTimer

    欢迎界面,还是比较简单的,一个UIScrollView控件,一个UIPageControl,几个UIImageView即可摆平.在这里光玩这些,就显得诚意不足了.特意拓展一下,再加几个UIButton ...

  9. iOS— UIScrollView和 UIPageControl之间的那些事

    本代码主要实现在固定的位置滑动图片可以切换. 目录图如下: ViewController.h #import <UIKit/UIKit.h> // 通过宏定义定义宽和高 #define W ...

  10. IOS初级:UIScrollView & UIPageControl

    UIScrollView其实构建的就像一列很长的火车,每滑动一个屏幕,展示一节车厢. //主屏幕高度 #define kScreenHeight [UIScreen mainScreen].bound ...

随机推荐

  1. GO 文件读取常用的方法

    方式1: 一行一行的方式读取 其中常用的方法就有:ReadString,ReadLine,ReadBytes ReadLine 返回单个行,不包括行尾字节,就是说,返回的内容不包括\n或者\r\n,返 ...

  2. 突然萌发关于 redis 的想法(2)

    接着上篇的说.. 上一篇 : 突然萌发关于 Redis 的想法(1) 今天写商城的时候突然发现,其实商城这种 频繁操作,频繁更新, 等操作,都只需要全部存储在 Redis 中就行了, 可能有部分数据会 ...

  3. BZOJ3678 wangxz与OJ (平衡树 无旋treap)

    题面 维护一个序列,支持以下操作: 1.在某个位置插入一段值连续的数. 2.删除在当前序列位置连续的一段数. 3.查询某个位置的数是多少. 题解 显然平衡树,一个点维护一段值连续的数,如果插入或者删除 ...

  4. 使用Spring PropertyPlaceholderConfigurer 配置中文出现乱码的解决方法

    在使用org.springframework.beans.factory.config.PropertyPlaceholderConfigurer 读取配置文件时,发现对于中文的处理会出现乱码现象,比 ...

  5. LOJ P10118 打鼹鼠 题解

    每日一题 day17 打卡 Analysis 二维树状数组的单点修改和区间查询,和一维的差不多 #include<iostream> #include<cstdio> #inc ...

  6. Oracle 11g 禁用 SQL Tuning Advisor 与 auto space advisor

    生产上有一套11g数据库alert.log报错ORA-16957: SQL Analyze time limit interrupt.  查询MOS相关文档Troubleshooting: ORA-1 ...

  7. zabbix数据的时序-

    gj的proxy服务器经过重启之后时序有变化. zabbix数据库中数据的存储是以哪方为准server端还是agent端, 触发事件跟恢复时间反了,本应该恢复的事件在数据库中查询event,得到的事件 ...

  8. java关于Integer设置-128到127的静态缓存

    今天在一个java群里,看到有个群友问到如下为什么第一个为true,第二个为false. System.out.println(Integer.valueOf("50")==Int ...

  9. sql server 发布订阅

    [配置] 一. 发布方 复制 >> 如果有问题 C:\Windows\System32\drivers\etc hosts: 127.0.0.1 ?? 二. 订阅方 订阅方设置结束 三. ...

  10. 如何用Deepin-wine安装运行win32的程序

    创建容器 容器就是win32程序运行的环境,可以理解为一个极小的windows,在Linux下面实际对应一个文件目录,如QQ对应的容器目录是~/.deepinwine/Deepin-QQ. 创建容器最 ...