At present, most apps will have a boot page at launch, today we introduce a more intuitive and fast implementation of the Guide page implementation method
The final effect is to have a full Screen guide page, at the bottom of the page is uipagecontrol to indicate the current boot page is the first few pages
The main use of two UI controls
Uipagecontrol *pagecontrol; Indicates that the page is currently on the Uiscrollview *scrollview;//for storing and displaying the boot page
First, get the screen size
Gets the screen width, height # define SCREEN_FRAME ([UIScreen mainscreen].bounds) #define SCREEN_WIDTH ([UIScreen mainscreen]. Bounds.size.width) #define Screen_height ([UIScreen mainscreen].bounds.size.height)
Initializing UI controls
Initialize 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, Ten)]; Pagecontrol.currentpageindicatortintcolor=[uicolor colorwithred:0.153 green:0.533 blue:0.796 alpha:1.0]; [Self.view Addsubview:pagecontrol]; pagecontrol.numberofpages=3;
We follow three guide pages to do, if need 4 5 pages can modify pagecontrol.numberofpages;
Create a three Uiimageview and initialize
<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]; }
Two other similar ways to achieve
Now it's the effect, but the switch between the boot pages hasn't come out yet.
You need to add an action to the image, when you click on the first image to switch to the page, click the second boot page to switch to the third boot page.
You need to use this to add an action to a picture, refer to
http://blog.csdn.net/lwjok2007/article/details/46388935
Or a first picture, for example, add another 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 methods
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 can be modeled as a secondary method
Final effect
Source
#import "ViewController.h"//Get screen width, 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 points to indicate which page of a multi-page view is currently displayed. Of course, because the Uipagecontrol class visual style is not very well clicked, it is a good idea to make sure that you have added the optional 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 paginated to display will make programming work faster. **/@interface Viewcontroller () {Uipagecontrol *pagecontrol;//indicates that it is currently in the first few boot pages Uiscrollview *scrollview;//for storing and displaying the boot page Uiimageview *imageviewone; Uiimageview *imageviewtwo; Uiimageview *imageviewthree; } @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Additional setup after loading the view, typically from a nib. Initialize 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]; UITapGestureRecognizer *SINGLETAP1 = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector ( Buttonpress1:)]; imageviewone.userinteractionenabled = YES; [Imageviewone ADDGESTURERECOGNIZER:SINGLETAP1]; [ScrollView Addsubview:view]; }-(void) createviewtwo{UIView *view = [[UIView alloc] Initwithframe:cgrectmake (Screen_width,0, Screen_width, screen_height)]; Imageviewtwo = [[Uiimageview alloc] initwithframe:screen_frame]; Imageviewtwo.contentmode = Uiviewcontentmodescaleaspectfit; Imageviewtwo.image = [UIImage imagenamed:@ "Helpsecond"]; [View Addsubview:imageviewtwo]; UITapGestureRecognizer *SINGLETAP1 = [[UITapGestureRecognizer 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_widt H, Screen_height)]; Imageviewthree = [[Uiimageview alloc] initwithframe:screen_frame]; Imageviewthree.contentmode = Uiviewcontentmodescaleaspectfit; Imageviewthree.image = [UIImage imagenamed:@ "Helpthree"]; [View Addsubview:imageviewthree]; UITapGestureRecognizer *SINGLETAP1 = [[UITapGestureRecognizer 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 complete"); }-(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
To facilitate the sharing of source code Exchange learning
Apple Development Group: 414319235 Welcome to Join
iOS boot page implementation (i)