zoukankan      html  css  js  c++  java
  • IOS引导页的编写

    我们在第一次打开App的时候,通常不是直接进入App主界面,而是会有一个能左右滑动、介绍App功能的界面。我是用NSUserDefaults + UIScrollview实现。
    新建一个类,继承UIView,假设名为Guide。在initWithFrame方法里:

      CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
      UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:frame];
      scrollView.backgroundColor = [UIColor whiteColor];
      scrollView.showsHorizontalScrollIndicator = NO;
      scrollView.showsVerticalScrollIndicator = NO;
      scrollView.contentSize = CGSizeMake(320*4, screenHeight);
      scrollView.pagingEnabled = YES;
      for (int i=0; i<4; i++) {
        UIImageView* imageView = [[UIImageView alloc initWithFrame:CGRectMake(i*320, 0, 320, screenHeight)];
      imageView.contentMode = UIViewContentModeScaleAspectFill;
    
      NSString *filePath = [[NSBundle mainBundle] pathForResource:
                  [NSString stringWithFormat:@"FileName"
                            ofType:@"FileType"];
      imageView.image = [UIImage imageWithContentsOfFile:filePath];
      [scrollView addSubview:imageView];
      if (i == 3) {
        UIButton* start = [UIButton buttonWithType:UIButtonTypeCustom];
        start.frame = CGRectMake(0, 0, 100, 44);
        start.layer.cornerRadius = 5;
        start.layer.borderWidth = 0.5;
        [start setCenter:CGPointMake(1120, iPhone5?450:400)];
        [start setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [start addTarget:self action:@selector(closeView) forControlEvents:UIControlEventTouchUpInside];
        [start setTitle:@"Start" forState:UIControlStateNormal];
        [scrollView addSubview:start];
      }
    

    这样,就有了一个有4张图片的引导页。
    怎么去判断是不是第一次登陆呢,需要用到NSUserDefaults类。
    在didFinishLaunchingWithOptions:函数中可以这样判断:

    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
    if([userDefaults objectForKey:@"FirstLoad"] == nil) {
        [userDefaults setBool:NO forKey:@"FirstLoad"];
        //显示引导页
    }
    
  • 相关阅读:
    Elasticsearch 检索
    Elasticsearch 基本操作
    Elasticsearch 集群
    Elasticsearch 插件head和kibana
    Elasticsearch 安装
    CentOS 安装JDK
    前端登录密码加密传输
    springboot2.0 快速集成kafka
    原来自定义模型绑定器还可以这么玩
    Value cannot be null or empty. 参数名: contentPath
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/4867890.html
Copyright © 2011-2022 走看看