文档章节

iOS引导页

hao1208hao
 hao1208hao
发布于 2016/07/28 11:52
字数 356
阅读 26
收藏 1

废话不多说,直接上代码。

定义一个引导页的类  GuideVC
GuideVC.h 文件:

#import
   @interface GuideVC : UIViewController
@end

GuideVC.m 文件:

#import "GuideVC.h"

#define totalCounts 3  //引导页数量
// 屏幕相关尺寸
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

@interface GuideVC ()

@property (strong, nonatomic)  UIScrollView *pageScroll;
@property (strong, nonatomic)  UIPageControl *pageControl;

@end

@implementation GuideVC

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self createScrollView];
}

// 创建显示引导图片ScrollView
-(void)createScrollView{   
    self.pageScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.pageScroll.pagingEnabled = YES;
    self.pageScroll.delegate = self;
    self.pageScroll.contentSize = CGSizeMake(SCREEN_WIDTH * totalCounts, SCREEN_HEIGHT);
    self.pageScroll.backgroundColor = [UIColor whiteColor];
    self.pageScroll.showsHorizontalScrollIndicator = NO;
    self.pageScroll.showsVerticalScrollIndicator = YES;
    [self.view addSubview:self.pageScroll];
   
   
    [self AddGuideImg];
   
    CGFloat w = 100;
    CGFloat h = 20;
    self.pageControl = [[UIPageControl alloc]init];
    [self.pageControl setFrame:CGRectMake((SCREEN_WIDTH-w)/2, SCREEN_HEIGHT-30, w, h)];
    self.pageControl.numberOfPages = totalCounts;  //设置引导页有几个界面
    self.pageControl.currentPage = 0;
    self.pageControl.tintColor = [UIColor lightGrayColor];
    [self.view addSubview:self.pageControl];
   
}


// 添加引导图片,图片全名  Guide1.jpg、Guide2.jpg、Guide3.jpg。。。
-(void)AddGuideImg{
    CGFloat height = [UIScreen mainScreen].bounds.size.height;
    for (int i=0; i
        UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i*SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        NSString* imageNameStr =[NSString stringWithFormat:@"Guide%i.jpg",i+1];
       
        imageView.image = [UIImage imageNamed:imageNameStr];
       
        if (i == totalCounts-1) {
            //最后一张图片添加按钮
            [imageView setUserInteractionEnabled:YES];
            UIButton* start = [UIButton buttonWithType:UIButtonTypeCustom];
            UIImage* startBtnImg = [UIImage imageNamed:@"btn"];
            [start setImage:startBtnImg forState:UIControlStateNormal];
           
            [start setFrame:CGRectMake(SCREEN_WIDTH-20-startBtnImg.size.width, SCREEN_HEIGHT-25-startBtnImg.size.height, startBtnImg.size.width, startBtnImg.size.height)];
           
            [start addTarget:self action:@selector(gotoMainView) forControlEvents:
             UIControlEventTouchUpInside];
            [imageView addSubview:start];           
        }
        [self.pageScroll addSubview:imageView];
    }   
}

//跳转到首页
-(void)gotoMainView{
  
}

#pragma mark - UIScrollViewDelegate
#pragma mark
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat pageWidth = self.view.frame.size.width;
    int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    self.pageControl.currentPage = page;
}

© 著作权归作者所有

共有 人打赏支持
hao1208hao
粉丝 0
博文 3
码字总数 2237
作品 0
石家庄
程序员
私信 提问

暂无文章

RestClientUtil和ConfigRestClientUtil区别说明

RestClientUtil directly executes the DSL defined in the code. ConfigRestClientUtil gets the DSL defined in the configuration file by the DSL name and executes it. RestClientUtil......

bboss
35分钟前
6
0

中国龙-扬科
昨天
1
0
Linux系统设置全局的默认网络代理

更改全局配置文件/etc/profile all_proxy="all_proxy=socks://rahowviahva.ml:80/"ftp_proxy="ftp_proxy=http://rahowviahva.ml:80/"http_proxy="http_proxy=http://rahowviahva.ml:80/"......

临江仙卜算子
昨天
5
0
java框架学习日志-6(bean作用域和自动装配)

本章补充bean的作用域和自动装配 bean作用域 之前提到可以用scope来设置单例模式 <bean id="type" class="cn.dota2.tpye.Type" scope="singleton"></bean> 除此之外还有几种用法 singleton:......

白话
昨天
8
0
在PC上测试移动端网站和模拟手机浏览器的5大方法

总结很全面,保存下来以备不时之需。原文地址:https://www.cnblogs.com/coolfeng/p/4708942.html

kitty1116
昨天
6
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部