iOS引导页
iOS引导页
hao1208hao 发表于1年前
iOS引导页
  • 发表于 1年前
  • 阅读 24
  • 收藏 1
  • 点赞 0
  • 评论 0

腾讯云 新注册用户 域名抢购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;
}

标签: iOS 引导页 滑屏
共有 人打赏支持
粉丝 0
博文 3
码字总数 2237
×
hao1208hao
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: