#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. 进程 multiprocessing Process join Lock Queue

    多道技术 1.空间上的复用 多个程序公用一套计算机硬件 2.时间上的复用 cpu 切换程序+保存程序状态 1.当一个程序遇到IO操作,操作系统会剥夺该程序的cpu执行权限(提高了cpu的利用率,并且不 ...

  2. [2019南昌邀请赛网络赛D][dp]

    https://nanti.jisuanke.com/t/38223 Xiao Ming recently indulges in match stick game and he thinks he ...

  3. 源码安装mongoDB

    1.安装启动 下载源码包,官方地址: wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.22.tgz 解压 ...

  4. 063_显示本机 Linux 系统上所有开放的端口列表

    #!/bin/bash#从端口列表中观测有没有没用的端口,有的话可以将该端口对应的服务关闭,防止意外的攻击可能性 ss -nutlp |awk '{print $1,$5}' | awk -F&quo ...

  5. openssl使用以及C#加密和数字签名

    如何使用openssl生成RSA公钥和私钥对 http://blog.csdn.net/scape1989/article/details/18959657 https://www.openssl ...

  6. polyfit 多项式曲线拟合matlab

    polyfit 多项式曲线拟合 全页折叠 语法 p = polyfit(x,y,n) [p,S] = polyfit(x,y,n) [p,S,mu] = polyfit(x,y,n)   说明 示例 ...

  7. java23种设计模式等等。。

    23种设计模式http://www.cnblogs.com/maowang1991/archive/2013/04/15/3023236.html 提升Java代码性能和安全性https://blog ...

  8. [bzoj 3534][Sdoi2014] 重建

    传送门 Description  T国有N个城市,用若干双向道路连接.一对城市之间至多存在一条道路. 在一次洪水之后,一些道路受损无法通行.虽然已经有人开始调查道路的损毁情况,但直到现在几乎没有消息传 ...

  9. Linux下java环境变量配置

    安装步骤 1.查看当前Linux系统是否安装java rpm -qa | grep java 2.卸载系统中已经存在的openJDK rpm -e --nodeps java--openjdk-1.7 ...

  10. 使用C#代码调用Web API

    1. POST POST的参数需要加上[FromBady],且参数只能一个 客户端提交数据的时候ContentType 为 application/x-www-form-urlencoded 或者 a ...