IOS 歡迎頁面(UIScrollView,UIPageControl),uipagecontrol

來源:互聯網
上載者:User

IOS 歡迎頁面(UIScrollView,UIPageControl),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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.