In the development of iOS, will involve the scrolling design of the page, in this I take the mobile phone scroll page design as an example to say briefly; specially prepared for beginners, the master will not have to read, because the content is too simple below for the design process, first declare the attribute in the. h file ViewController.h#import <UIKit/UIKit.h>
Macro defines the width and height of the phone screen; note: The end of the macro definition cannot be signed ";".
#define Width Self.view.frame.size.width
#define Height Self.view.frame.size.height There is no need to set a macro definition here,@interface Viewcontroller:uiviewcontroller<
uiscrollviewaccessibilitydelegate>//here is a declaration that follows the proxy//attribute; @property (strong,nonatomic) uiscrollview *myscrollview;//slide View
@property (strong,nonatomic) Uipagecontrol *mypagecontrol;//page control
@endIn the. m file
viewcontroller.m
#import "ViewController.h"
@interface Viewcontroller ()
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Create a bottom screen panel
Self.myscrollview=[[uiscrollview alloc]initwithframe:cgrectmake (0, 0, Width, Height)];
Self.myscrollview.backgroundcolor=[uicolor Graycolor];
Content Panel Size
Self.myscrollview. Contentsize=cgsizemake (414, 736);
Specify Proxy
self.myscrollview.delegate=self;
Add image 1
Uiimageview *imageview1=[[uiimageview alloc]initwithframe:cgrectmake (0, 0, 414, 700)];
Imageview1.image=[uiimage imagenamed:@ "/users/scjy/desktop/uipickview/uipickview/image/screenshot 2016-03-09 PM 1.22.21.png "];
Add Image 2
Uiimageview *imageview2=[[uiimageview alloc]initwithframe:cgrectmake (414, 0, 414, 700)];
Imageview2.image=[uiimage imagenamed:@ "/users/scjy/desktop/uipickview/uipickview/image/screenshot 2016-03-09 PM 1.23.16.png "];
Add Image 3
Uiimageview *imageview3=[[uiimageview alloc]initwithframe:cgrectmake (414*2, 0, 414,700)];
Imageview3.image=[uiimage imagenamed:@ "/users/scjy/desktop/uipickview/uipickview/image/screenshot 2016-03-09 PM 1.24.13.png "];
Add Image 3
Uiimageview *imageview4=[[uiimageview alloc]initwithframe:cgrectmake (414*3, 0, 414,700)];
Imageview4.image=[uiimage imagenamed:@ "/users/scjy/desktop/uipickview/uipickview/image/screenshot 2016-03-09 PM 1.33.30.png "];
Add Image 3
Uiimageview *imageview5=[[uiimageview alloc]initwithframe:cgrectmake (414*4, 0, 414,700)];
Imageview5.image=[uiimage imagenamed:@ "/users/scjy/desktop/uipickview/uipickview/image/screenshot 2016-03-09 PM 1.50.36.png "];
Add a picture with the screen panel
[Self.myscrollview Addsubview:imageview1];
[Self.myscrollview Addsubview:imageview2];
[Self.myscrollview ADDSUBVIEW:IMAGEVIEW3];
[Self.myscrollview ADDSUBVIEW:IMAGEVIEW4];
[Self.myscrollview ADDSUBVIEW:IMAGEVIEW5];
To add a screen panel to a view
[Self.view AddSubview:self.myScrollView];
Lock Scroll Direction
Self.myscrollview.directionallockenabled=no;
Decide whether to set page pagination for panel screen ....
Self.myscrollview.pagingenabled=yes;
Determines whether scroll bars are displayed
Self.myscrollview. Showshorizontalscrollindicator=no;
Page control buttons
Self.mypagecontrol=[[uipagecontrol Alloc]init];
Cgsize Pagesize=cgsizemake (120, 20);
Self.mypagecontrol.frame=cgrectmake (Width-pagesize.width)/2, height-pagesize.height-40, PageSize.width, Pagesize.height); Self.mypagecontrol.backgroundcolor=[uicolor Graycolor]; Set the number of pages to scroll
self.mypagecontrol.numberofpages=5;
Set the number of pages initially displayed self.mypagecontrol.currentpage=0; [Self.view addsubview:self. Mypagecontrol];
}
Method implementation of Proxy delegate
-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView
{
self.mypagecontrol.currentpage= (int) (scrollview.contentoffset.x/width);
NSLog (@ "%@", ScrollView);
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}
The final effect of @end design is to slide to different page effects as follows: 1th Page 2nd page
iOS Design-scrolling page design (Control Uiscrollview)