zoukankan      html  css  js  c++  java
  • IOS 欢迎页(UIScrollView,UIPageControl)

    本文介绍了app欢迎页的简单实现。只有第一次运行程序时才说会出现,其余时间不会出现。下面是效果图。

    代码如下:(如有不明白的可以评论我,我会详细讲解)

    //
    //  ViewController.m
    //  CX IOS欢迎页
    //
    //  Created by ma c on 16/3/18.
    //  Copyright © 2016年 xubaoaichiyu. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()<UIScrollViewDelegate>
    
    @property (nonatomic, strong) UIScrollView * scrollView;
    @property (nonatomic, strong) UIPageControl * pageControl;
    
    @end
    
    @implementation ViewController
    #pragma mark - life
    - (void)viewDidLoad {
        [super viewDidLoad];
       //判断是否是第一次运行程序
        NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
    //    [userDefaults removeObjectForKey:@"FirstLoad"];
        if ([userDefaults objectForKey:@"FirstLoad"] == nil) {
            [userDefaults setBool:NO forKey:@"FirstLoad"];
            [self loadScrollView];
        }
        
        
        
    }
    #pragma mark - deleDate
    
    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
        
        CGPoint point = self.scrollView.contentOffset;
        
        NSInteger current = point.x / self.view.frame.size.width;
        
        self.pageControl.currentPage = current;
        
    }
    
    #pragma mark - function
    -(void)loadScrollView{
        
        CGRect rect = [UIScreen mainScreen].bounds;
        
        self.scrollView = [[UIScrollView alloc]initWithFrame:rect];
        //分页
        self.scrollView.pagingEnabled = YES;
        
        self.scrollView.delegate = self;
        
        self.scrollView.showsHorizontalScrollIndicator = NO;
        
        self.scrollView.showsVerticalScrollIndicator = NO;
        //scrollView滚动区域大小
        self.scrollView.contentSize = CGSizeMake(rect.size.width * 4, rect.size.height);
        
        for (NSInteger i = 0; i < 4; i ++) {
            
            UIImageView * imageView = [[UIImageView alloc]init];
            
            imageView.frame = CGRectMake(i * rect.size.width, 0, rect.size.width, rect.size.height);
            //为了区别imageView而又简单操作,建立随机颜色。
            imageView.backgroundColor = [UIColor colorWithRed:arc4random() % 255 / 255.f green:arc4random() % 255 / 255.f blue:arc4random() % 255 / 255.f alpha:1];
            [self.scrollView addSubview:imageView];
            
            //添加开启软件
            UIButton * removeBUtton = [UIButton buttonWithType:UIButtonTypeCustom];
            
            removeBUtton.frame = CGRectMake(150 + 3 * rect.size.width, rect.size.height * 0.7, rect.size.width - 300, 30);
            
            [removeBUtton setTitle:@"开启旅行" forState:UIControlStateNormal];
            
            [removeBUtton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            
            removeBUtton.backgroundColor = [UIColor orangeColor];
            
            [removeBUtton addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
            
            [self.scrollView addSubview:removeBUtton];
        }
        
        [self.view addSubview:self.scrollView];
        
        [self loadPageControl];
        
    }
    
    -(void)start{
        
        [self.pageControl removeFromSuperview];
        
        [self.scrollView removeFromSuperview];
        
    }
    -(void)loadPageControl{
        
        CGRect rect = [UIScreen mainScreen].bounds;
        
        self.pageControl = [[UIPageControl alloc]init];
        
        self.pageControl.numberOfPages = 4;
        
        CGSize pageControlSize = [self.pageControl sizeForNumberOfPages:4];
        
        self.pageControl.frame = CGRectMake((rect.size.width - pageControlSize.width) / 2, rect.size.height * 0.8, pageControlSize.width, pageControlSize.height);
        
        self.pageControl.currentPage = 0;
        
        self.pageControl.currentPageIndicatorTintColor = [UIColor greenColor];
        
        self.pageControl.pageIndicatorTintColor = [UIColor grayColor];
        
        [self.view addSubview:self.pageControl];
        
        [self.view bringSubviewToFront: self.pageControl];
        
    }
    @end
  • 相关阅读:
    Arcengine效率探究之二——属性的更新 转载
    ArcEngine GDB数据库查询方法总结 转载
    黄聪:Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
    arcgis10.1补丁下载
    arcgis 分式标注jscript "<und>"+ [DLBM] +"</und>"+ "\r\n" + [DLMC]
    arcgis开发,C盘磁盘空间消失元凶,让c盘可以多出10G
    arcgis 查询 group by order by
    arcgis jscript参考http://technet.microsoft.com/zhcn/library/997bcd30(v=vs.80)
    在ArcEngine下实现图层属性过滤的两种方法 转载http://www.gisall.com/html/72/1242722990.html
    使用Geoprocessor 计算面积和长度 转载
  • 原文地址:https://www.cnblogs.com/xubaoaichiyu/p/5293656.html
Copyright © 2011-2022 走看看