123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- //
- // XTGuidePagesViewController.m
- // XTGuidePagesView
- //
- // Created by zjwang on 16/5/30.
- // Copyright © 2016年 夏天. All rights reserved.
- //
- #import "XTGuidePagesViewController.h"
- #define s_w [UIScreen mainScreen].bounds.size.width
- #define s_h [UIScreen mainScreen].bounds.size.height
- @interface XTGuidePagesViewController ()<UIScrollViewDelegate>
- @property (nonatomic, strong) UIPageControl *pageControl;
- @end
- @implementation XTGuidePagesViewController
- - (void)guidePageControllerWithImages:(NSArray *)images AndTitle:(NSArray *)titles Andtipe:(NSArray *)tipes
- {
- UIScrollView *gui = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, s_w, s_h)];
- gui.delegate = self;
- gui.pagingEnabled = YES;
- // 隐藏滑动条
- gui.showsHorizontalScrollIndicator = NO;
- gui.showsVerticalScrollIndicator = NO;
- // 取消反弹
- gui.bounces = NO;
- for (NSInteger i = 0; i < images.count; i ++) {
- [gui addSubview:({
- self.btnEnter = [UIButton buttonWithType:UIButtonTypeCustom];
- self.btnEnter.frame = CGRectMake(s_w * i, 0, s_w, s_h);
- [self.btnEnter setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];
-
- UIImageView *img =[[UIImageView alloc]initWithFrame:CGRectMake( FITSIZE(10), (SCREEN_HEIGHT-s_w+FITSIZE(20))/2-FITSIZE(60), s_w-FITSIZE(20), s_w-FITSIZE(20))];
- img.image =[UIImage imageNamed:[NSString stringWithFormat:@"ydy-%d",i+1]];
- [self.btnEnter addSubview:img];
-
- UILabel *label1 =[[UILabel alloc]initWithFrame:CGRectMake(0, (SCREEN_HEIGHT-s_w-FITSIZE(30))/2+s_w-FITSIZE(20), SCREEN_WIDTH, FITSIZE(30))];
- label1.text=titles[i];
- label1.textColor=[UIColor whiteColor];
- [self.btnEnter addSubview:label1];
- if (@available(iOS 8.2, *)) {
- label1.font =[UIFont systemFontOfSize:FITSIZE(30) weight:FITSIZE(1)];
- } else {
- label1.font =[UIFont systemFontOfSize:FITSIZE(30)];
- }
- label1.textAlignment=NSTextAlignmentCenter;
-
-
- UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(0, (SCREEN_HEIGHT-s_w+FITSIZE(60))/2+s_w-FITSIZE(20), SCREEN_WIDTH, FITSIZE(30))];
- label.text=tipes[i];
- label.textColor=[UIColor whiteColor];
- label.font =[UIFont systemFontOfSize:FITSIZE(24)];
- label.textAlignment=NSTextAlignmentCenter;
- [self.btnEnter addSubview:label];
-
- self.btnEnter;
- })];
-
- [self.btnEnter addSubview:({
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- if (i == images.count - 1) {
- [btn setTitle:@"马上体验" forState:UIControlStateNormal];
- btn.hidden =NO;
- }else{
- btn.hidden=YES;
- }
- btn.highlighted=NO;
- btn.frame = CGRectMake(s_w * i, s_h - 65, 130, 40);
- btn.center = CGPointMake(s_w / 2, s_h - 5-TabbarHeight);
- btn.layer.cornerRadius = 4;
- btn.clipsToBounds = YES;
- [btn setTitleColor:[UIColor homeRedColor] forState:UIControlStateNormal];
- btn.backgroundColor = [UIColor whiteColor];
- [btn addTarget:self action:@selector(clickEnter) forControlEvents:UIControlEventTouchUpInside];
- btn;
- })];
- }
- gui.contentSize = CGSizeMake(s_w * images.count, 0);
- [self.view addSubview:gui];
-
- // pageControl
- self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, s_w / 2, 30)];
- self.pageControl.center = CGPointMake(s_w / 2, s_h - BottomMargin-15);
- [self.view addSubview:self.pageControl];
- self.pageControl.numberOfPages = images.count;
- }
- - (void)clickEnter
- {
- if (self.delegate != nil && [self.delegate respondsToSelector:@selector(clickEnter)]) {
- [XTGuidePagesViewController saveCurrentVersion];
- [self.delegate clickEnter];
-
- }
- }
- + (BOOL)isShow
- {
- // 读取版本信息
- NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
- NSString *localVersion = [user objectForKey:VERSION_INFO_CURRENT];
-
- NSString *currentVersion =[[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
- if (localVersion == nil || ![currentVersion isEqualToString:localVersion]) {
-
- return YES;
- }else
- {
- return NO;
- }
- }
- // 保存版本信息
- + (void)saveCurrentVersion
- {
- NSString *version =[[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
- NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
- [user setObject:version forKey:VERSION_INFO_CURRENT];
-
- [user synchronize];
- }
- #pragma mark - ScrollerView Delegate
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
- {
- self.pageControl.currentPage = scrollView.contentOffset.x / s_w;
- }
- @end
|