#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

启动图实现:UIScrollView+UIPageControl简单实现的更多相关文章

  1. swift开发之 -- 自动轮播图(UIScrollView+UIPageControl+Timer)

    比较简单,原理就不说了,这里只做记录: 代码如下: 1,准备 var pageControl:UIPageControl? var myscrollView:UIScrollView? var myT ...

  2. iOS加载启动图的时候隐藏statusbar + 指定启动图显示多少秒

    只需需要在info.plist中加入Status bar is initially hidden 设置为YES 补充一下,现在手机越来越快,在6+下面启动图一闪而过,而美工童鞋辛辛苦苦做的图就看不到鸟 ...

  3. iOS LaunchScreen和LaunchImage的转换启动图

    今天开始设置一个新项目的启动图,需要我自己设置,我在UI那拿到以前格式的启动图不知道为何需要那么多图,我记得用LaunchScreen只需一张即可,利用自动布局,今天看到这么多图,发现他用的是Laun ...

  4. iOS开发简记(1):指定APP的图标与启动图

    各位兄弟姐妹们,早上好,本人花了将近一个月的时间打造了一个完整的IOS版的App, 期间包括开发,测试,上线审核,现在花点时间把实现的过程分享给大家,“知音”app功能简单,适合对象为初学者,后面我会 ...

  5. Mac生成APP图标和启动图的脚本

    概述 之前用的一个批量导出APP图标和启动图的软件,今天发现收费了,于是自己造了个简单的轮子. 实现 Mac上的sips命令,可以很方便的帮助用户修改图片尺寸 Xcode里面的APP启动图资源包含两部 ...

  6. Qt实现炫酷启动图-动态进度条

    目录 一.简述 二.动效进度条 1.光效进度条 2.延迟到达进度条 3.接口说明 三.启动图 1.实现思路 2.背景图切换 四.测试 1.构造启动图 2.背景图 3.其他信息 4.事件循环 五.源码 ...

  7. 用launchscreen.storyboard适配启动图方法(二)

    背景 之前有写一篇实现方式比较简单的随笔用launchscreen.storyboard适配启动图方法,顺便在评论区提了一下用autolayout适配启动图的思路,现把思路和流程记录下来. 思路 整体 ...

  8. Safari配置WebApp----添加启动图和桌面图标让你的WebApp在ios设备上体验如原生一样

    现在很多开发者的Web应用程序的设计样式和交互类似本机应用程序,例如,它的缩放比例适合iOS上的整个屏幕.当用户将其添加到主屏幕时,您可以通过使其看起来像本机应用程序一样,在iOS上为您的Web应用程 ...

  9. flutter添加启动图及设置启动时间

    首先贴个官方的设置方法,看这里:https://flutterchina.club/assets-and-images/#%E6%9B%B4%E6%96%B0%E5%90%AF%E5%8A%A8%E9 ...

随机推荐

  1. Eclipse Svn 取消某些文件或文件夹的版本控制

    SVN提交时,我们有时候需要将一些文件忽略掉,例如:maven项目中的target文件夹,可以将这些文件或文件夹设置成ignore来忽略这些文件或文件夹 1. 将文件夹或文件从Eclipse中删除.记 ...

  2. TCP & UDP & IP

    TCP和UDP的区别   TCP UDP 是否连接 面向连接 面向非连接 应用场合 可靠的 不可靠的 速度 慢 快 传送数据 字节流 数据报 是否可用于广播 否 是 为什么UDP比TCP快 不需要连接 ...

  3. 【转载】4412开发板、PC、ubuntu通过网线连接

    今天看到使用TFTP方式,开发板直接从ubuntu下载程序,不需要一直通过烧写文件系统下载,我试了一下,虚拟机.开发板.pc三者老是互相ping不通.纠结了很久终于解决了. 写下这个小笔记,供大家参考 ...

  4. SQOOP Load Data from Oracle to Hive Table

    sqoop import -D oraoop.disabled=true \ --connect "jdbc:oracle:thin:@(description=(address=(prot ...

  5. 探索 OpenStack 之(9):深入块存储服务Cinder (功能篇)

    继研究了Neutron之后,继续Nova的外围研究之旅.本站是研究块存储服务Cinder. 0.验证环境 环境包括: 1.一个controller节点,运行nova-api, nova-schedul ...

  6. Medial Queries的另一用法:实现IE hack的方法

    所谓Medial Queries就是媒体查询. 随着Responsive设计的流行,Medial Queries可算是越来越让人观注了.他可以让Web前端工程实现不同设备下的样式选择,让站点在不同的设 ...

  7. div中的内容垂直居中的五种方法

    一.行高(line-height)法 如果要垂直居中的只有一行或几个文字,那它的制作最为简单,只要让文字的行高和容器的高度相同即可,比如: p { height:30px; line-height:3 ...

  8. 2014 Super Training #10 C Shadow --SPFA/随便搞/DFS

    原题: FZU 2169 http://acm.fzu.edu.cn/problem.php?pid=2169 这题貌似有两种解法,DFS和SPFA,但是DFS怎么都RE,SPFA也要用邻接表表示边, ...

  9. 第52课 C++中的抽象类和接口

    1. 什么是抽象类 (1)面向对象中的抽象概念 思考:抽象图形中,图形的面积如何计算? (2)现实中:需要知道具体的图形类型,才能求面积. (3)Shape只是一个概念上的类型,没有具体对象 2. 面 ...

  10. AC日记——热浪 codevs 1557 (最短路模板题)

    1557 热浪  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 德克萨斯纯朴的民眾们这个夏 ...