#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. android 进程间通信---Service Manager(2)

    关于servicemanager的设计: 还是这张结构图,由于ProcessState & IPCThreadState是与binder deriver交互的, 所以对于client端来说Bp ...

  2. Mongodb在Windows上的配置

    1.打开mongodb的官网:https://www.mongodb.org/进行下载相应平台的安装包 2.我们选择最新版的3.2版本来下载,选择对应的操作系统版本来下载,这里选择windows Mo ...

  3. rails开发demo(一)搭建环境

    环境 ubuntu 14.04 为了安装rails4.2 和 ruby 2.2.2,这是目前稳定的最新版本,需要先安装rvm sudo apt-get update sudo apt-get inst ...

  4. GridControl控件的数据显示的样式控制(转)

    如上两图所示,Dev列表控件GridControl默认的格式并没有渐变变色效果,显示的日期数据,也是“yyyy-MM-dd”的格式,而非“yyyy-MM-dd HH:mm:ss”即使对于后面有长格式的 ...

  5. MySQL的replace函数的用法

    REPLACE(field,find_str,replace_str): 字段field的内容中的find_str 将被 替换为 replace_str . 例如: update short_url ...

  6. oracle错误(ORA-01691),单个数据文件大小限制问题

    1.问题:数据库从其他库同步一张大表时,出现错误 ERROR at line : ORA-: illegal parameter value in OCI lob function ORA-: pre ...

  7. fis自动化部署

    1,自动部署到远程服务器 (1),参考:https://github.com/fex-team/receiver (2),接收服务代码目录:/var/www/html/fis/receiver-mas ...

  8. UC 浏览器远程调试手机web网页记录

    浏览器远程调试插件有很多,本来要使用chrome浏览器的调试插件的,但是需要FQ才能使用(公司网络有限制,果断放弃),最终选择使用UC浏览器的. 其实UC官网插件使用已经介绍的很详细了,但是有几处坑需 ...

  9. JavaScript 题目破解过程与解析

    题目来源 https://www.hackthissite.org/missions/javascript/ HackThisSite JavaScript mission 1-7 1 我先尝试输入  ...

  10. 迅为三星Exynos 4412开发板四核Cortex-A9ARM安卓linux开发板

    开发板光盘资料包含:原理图(PDF格式).底板PCB(Allegro格式).驱动程序源码.芯片和LCD数据手册.开发环境.产品使用手册. 4412开发板简介: iTOP-Exynos4412开发板采用 ...