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