启动图实现: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
启动图实现:UIScrollView+UIPageControl简单实现的更多相关文章
- swift开发之 -- 自动轮播图(UIScrollView+UIPageControl+Timer)
比较简单,原理就不说了,这里只做记录: 代码如下: 1,准备 var pageControl:UIPageControl? var myscrollView:UIScrollView? var myT ...
- iOS加载启动图的时候隐藏statusbar + 指定启动图显示多少秒
只需需要在info.plist中加入Status bar is initially hidden 设置为YES 补充一下,现在手机越来越快,在6+下面启动图一闪而过,而美工童鞋辛辛苦苦做的图就看不到鸟 ...
- iOS LaunchScreen和LaunchImage的转换启动图
今天开始设置一个新项目的启动图,需要我自己设置,我在UI那拿到以前格式的启动图不知道为何需要那么多图,我记得用LaunchScreen只需一张即可,利用自动布局,今天看到这么多图,发现他用的是Laun ...
- iOS开发简记(1):指定APP的图标与启动图
各位兄弟姐妹们,早上好,本人花了将近一个月的时间打造了一个完整的IOS版的App, 期间包括开发,测试,上线审核,现在花点时间把实现的过程分享给大家,“知音”app功能简单,适合对象为初学者,后面我会 ...
- Mac生成APP图标和启动图的脚本
概述 之前用的一个批量导出APP图标和启动图的软件,今天发现收费了,于是自己造了个简单的轮子. 实现 Mac上的sips命令,可以很方便的帮助用户修改图片尺寸 Xcode里面的APP启动图资源包含两部 ...
- Qt实现炫酷启动图-动态进度条
目录 一.简述 二.动效进度条 1.光效进度条 2.延迟到达进度条 3.接口说明 三.启动图 1.实现思路 2.背景图切换 四.测试 1.构造启动图 2.背景图 3.其他信息 4.事件循环 五.源码 ...
- 用launchscreen.storyboard适配启动图方法(二)
背景 之前有写一篇实现方式比较简单的随笔用launchscreen.storyboard适配启动图方法,顺便在评论区提了一下用autolayout适配启动图的思路,现把思路和流程记录下来. 思路 整体 ...
- Safari配置WebApp----添加启动图和桌面图标让你的WebApp在ios设备上体验如原生一样
现在很多开发者的Web应用程序的设计样式和交互类似本机应用程序,例如,它的缩放比例适合iOS上的整个屏幕.当用户将其添加到主屏幕时,您可以通过使其看起来像本机应用程序一样,在iOS上为您的Web应用程 ...
- flutter添加启动图及设置启动时间
首先贴个官方的设置方法,看这里:https://flutterchina.club/assets-and-images/#%E6%9B%B4%E6%96%B0%E5%90%AF%E5%8A%A8%E9 ...
随机推荐
- Windows Server 2012 R2下通过80端口访问Odoo ERP
背景 Odoo 9.0系统,安装于Windows Server 2012R2,同时与IIS并存.Odoo自带web服务器,使用端口8069.因客户需要用80端口访问,因此需要进一步设置,且8069端口 ...
- MyCat 学习笔记 第六篇.数据分片 之 按月数据分片
1 应用场景 Mycat 有很多数据分库规则,接下来几篇就相关觉得常用的规则进行试用与总结. 一般来说,按自然月份来进行数据分片的规则比较适用于商城订单查询,类似最近1周.2周.3个月内的数据.或是报 ...
- ASP.NET导出bdf文件
1.导出助手类 using System;using System.IO;using System.Data;using System.Data.OleDb;using System.Web;usin ...
- kvm解决1000M网卡问题
1.当我们安装完虚拟机, 发现虚拟机竟然是 100M 网络, 传输速率很低, 那是怎么导致的呢,如何来解决呢? 需要我们修改 vm01.xml 配置文件网卡段,添加如下红色标记行,改 为 e1000, ...
- 有用的MySQL语句
摘自onefish资料库 1. 计算年数你想通过生日来计算这个人有几岁了. SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(now()) - TO_DAYS(@dateofb ...
- uva 10305 ordering tasks(超级烂题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABHIAAAHDCAYAAABI5T2bAAAgAElEQVR4nOydPY7svLW1awQGNABHCm
- runv kill 流程分析
1.runv/kill.go Action: func(context *cli.Context) 该函数做的工作很简单,就是通过grpc客户端,发送一个grpc请求而已,如下: c.Signal(n ...
- LeetCode 1 Two Sum 解题报告
LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...
- 使用nmon监控服务器性能
1.下载nmon:http://nmon.sourceforge.net/pmwiki.php?n=Site.Download 2.选择适合Linux系统版本的相应nmon版本,Linux查看系统版本 ...
- iOS使用Core Graphics和UIBezierPath绘画
通过UIView的子类的- (void)drawRect:(CGRect)rect 函数可用对视图进行重新绘画: 要重新绘画可以通过Core Graphics和UIBezierPath来实现. 1.通 ...