IOS boot page implementation (1), ios boot implementation
At present, most apps will have boot pages at startup. Today we will introduce you to a more intuitive and fast implementation of boot pages.
The final result is a full-screen boot page with UIPageControl at the bottom of the page to indicate which pages the current Boot page is
Two UI controls are used.
UIPageControl * pageControl; // indicates which boot pages are currently in UIScrollView * scrollView; // used to store and display the boot page
First, obtain the screen size.
// Obtain the screen width and height # define SCREEN_FRAME ([UIScreen mainScreen]. bounds) # define SCREEN_WIDTH ([UIScreen mainScreen]. bounds. size. width) # define SCREEN_HEIGHT ([UIScreen mainScreen]. bounds. size. height)
Initialize the UI control
// Initialize the UI control scrollView = [[UIScrollView alloc] initWithFrame: SCREEN_FRAME]; scrollView. pagingEnabled = YES; [self. view addSubview: scrollView]; pageControl = [[UIPageControl alloc] initWithFrame: CGRectMake (0, SCREEN_HEIGHT-50, SCREEN_WIDTH, 10)]; pageControl. currentPageIndicatorTintColor = [UIColor colorWithRed: 0.153 green: 0.533 blue: 0.796 alpha: 1.0]; [self. view addSubview: pageControl]; pageControl. numberOfPages = 3;
We will follow three boot pages. If you need four or five pages, you can modify pageControl. numberofPages;
Create three uiimageviews and initialize them.
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 15px; font-family: Menlo;"> <span style="font-size: 11px; color: rgb(112, 61, 170);">UIImageView</span> *imageViewOne;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 15px; font-family: Menlo;"> <span style="font-size: 11px; color: rgb(112, 61, 170);">UIImageView</span> *imageViewTwo;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 15px; font-family: Menlo;"> <span style="font-size: 11px; color: rgb(112, 61, 170);">UIImageView</span> *imageViewThree;</p>
Initialize the first UIImageView
-(void)createViewOne{ UIView *view = [[UIView alloc] initWithFrame:SCREEN_FRAME]; imageViewOne = [[UIImageView alloc] initWithFrame:SCREEN_FRAME]; imageViewOne.contentMode = UIViewContentModeScaleAspectFit; imageViewOne.image = [UIImage imageNamed:@"HelpFrist"]; [view addSubview:imageViewOne]; [scrollView addSubview:view]; }
The other two methods are similar.
At present, the results have come out, but the switching between boot pages has not yet come out.
Next, you need to add an action to the image. When you click the first image, switch to the first boot page, and click the second boot page to switch to the third boot page.
You need to add actions to the image. For more information, see
Http://blog.csdn.net/lwjok2007/article/details/46388935
The first image is used as an example to add a piece of code to the createViewOne method above.
-(void)createViewOne{ UIView *view = [[UIView alloc] initWithFrame:SCREEN_FRAME]; imageViewOne = [[UIImageView alloc] initWithFrame:SCREEN_FRAME]; imageViewOne.contentMode = UIViewContentModeScaleAspectFit; imageViewOne.image = [UIImage imageNamed:@"HelpFrist"]; [view addSubview:imageViewOne]; UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonpress1:)]; imageViewOne.userInteractionEnabled = YES; [imageViewOne addGestureRecognizer:singleTap1]; [scrollView addSubview:view]; }
Simultaneous implementation
Buttonpress1
#pragma mark -- tap image-(void)buttonpress1:(id)sender{ CGFloat pageWidth = CGRectGetWidth(self.view.bounds); CGPoint scrollPoint = CGPointMake(pageWidth, 0); [scrollView setContentOffset:scrollPoint animated:YES]; pageControl.currentPage = 1; }
The other two methods can be used.
Final Effect
Source code
# Import "ViewController. h "// obtain the screen width and height # define SCREEN_FRAME ([UIScreen mainScreen]. bounds) # define SCREEN_WIDTH ([UIScreen mainScreen]. bounds. size. width) # define SCREEN_HEIGHT ([UIScreen mainScreen]. bounds. size. height)/** the UIPageControl class provides a line of vertices to indicate which page of the Multi-page view is currently displayed. Of course, because the click of the UIPageControl visual style is not very good, it is best to ensure that you have added selectable navigation options to make the page control look more like an indicator than a control. When the user interface needs to be displayed by PAGE, using the UIPageControl Control to display the user interface content by page will make programming work faster. **/@ Interface ViewController () {UIPageControl * pageControl; // indicates which boot pages are currently in UIScrollView * scrollView; // It is used to store and display the boot page UIImageView * imageViewOne; UIImageView * imageViewTwo; UIImageView * imageViewThree;} @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // initialize the UI control scrollView = [[UIScrollView alloc] initWithFrame: SCREEN_FRAME]; scrollView. pagingEnabled = YES; [self. view addSubview: scrollView]; pageControl = [[UIPageControl alloc] initWithFrame: CGRectMake (0, SCREEN_HEIGHT-50, SCREEN_WIDTH, 10)]; pageControl. currentPageIndicatorTintColor = [UIColor colorWithRed: 0.153 green: 0.533 blue: 0.796 alpha: 1.0]; [self. view addSubview: pageControl]; pageControl. numberOfPages = 3; [self createViewOne]; [self createViewTwo]; [self createViewThree];}-(void) createViewOne {UIView * view = [[UIView alloc] initWithFrame: SCREEN_FRAME]; imageViewOne = [[UIImageView alloc] initWithFrame: SCREEN_FRAME]; imageViewOne. contentMode = UIViewContentModeScaleAspectFit; imageViewOne. image = [UIImage imageNamed: @ "HelpFrist"]; [view addSubview: imageViewOne]; optional * singleTap1 = [[using alloc] initWithTarget: self action: @ selector (buttonpress1 :)]; imageViewOne. userInteractionEnabled = YES; [imageViewOne progress: singleTap1]; [scrollView addSubview: view];}-(void) createViewTwo {UIView * view = [[UIView alloc] Progress: CGRectMake (SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; imageViewTwo = [[UIImageView alloc] initWithFrame: SCREEN_FRAME]; imageViewTwo. contentMode = UIViewContentModeScaleAspectFit; imageViewTwo. image = [UIImage imageNamed: @ "helrentcond"]; [view addSubview: imageViewTwo]; optional * singleTap1 = [[using alloc] initWithTarget: self action: @ selector (buttonpress2 :)]; imageViewTwo. userInteractionEnabled = YES; [imageViewTwo addGestureRecognizer: singleTap1]; [scrollView addSubview: view];}-(void) createViewThree {UIView * view = [UIView alloc] initWithFrame: CGRectMake (SCREEN_WIDTH * 2, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; imageViewThree = [[UIImageView alloc] initWithFrame: SCREEN_FRAME]; imageViewThree. contentMode = UIViewContentModeScaleAspectFit; imageViewThree. image = [UIImage imageNamed: @ "HelpThree"]; [view addSubview: imageViewThree]; optional * singleTap1 = [[using alloc] initWithTarget: self action: @ selector (buttonpress3 :)]; imageViewThree. userInteractionEnabled = YES; [imageViewThree addGestureRecognizer: singleTap1]; [scrollView addSubview: view] ;}# pragma mark -- tap image-(void) buttonpress1 :( id) sender {CGFloat pageWidth = CGRectGetWidth (self. view. bounds); CGPoint scrollPoint = CGPointMake (pageWidth, 0); [scrollView setContentOffset: scrollPoint animated: YES]; pageControl. currentPage = 1 ;}- (void) buttonpress2 :( id) sender {CGFloat pageWidth = CGRectGetWidth (self. view. bounds); CGPoint scrollPoint = CGPointMake (pageWidth * 2, 0); [scrollView setContentOffset: scrollPoint animated: YES]; pageControl. currentPage = 2;}-(void) buttonpress3 :( id) sender {NSLog (@ "Boot page completed");}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end
To facilitate shared source code communication and learning
Apple Development Group: 414319235 welcome to join