IOS welcome page (UIScrollView, UIPageControl), uipagecontrol

Source: Internet
Author: User

IOS welcome page (UIScrollView, UIPageControl), uipagecontrol

This article introduces the simple implementation of the app welcome page. It appears only when the program is run for the first time, but not for the rest of the time. Below is.

The Code is as follows: (if you do not understand it, you can comment on me. I will explain it in detail)

/// ViewController. m // cx ios welcome page /// 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]; // determine whether the program is running for the first time NSUserDefaults * userDefaults = [NSUserDefaults standardUs ErDefaults]; // [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]; // page self. scrollView. pagingEnabled = YES; self. scrollView. delegate = self; self. scrollView. showsHorizontalScrollIndicator = NO; self. scrollView. showsVerticalScrollIndicator = NO; // scrollView rolling area size 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); // creates a random color for distinguishing imageView with simple operations. ImageView. backgroundColor = [UIColor colorWithRed: arc4random () % 255/255 .f green: arc4random () % 255/255 .f blue: arc4random () % 255/255 .f alpha: 1]; [self. scrollView addSubview: imageView]; // Add the enable software 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: @ "enable travel" 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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.