</pre> Explain the tools I do: Mac OS X virtual machine 10.9.3 xcode6 Baidu ^-^ Reference IPhone30 Day Mastery: This program is the 13th day + 14th Day Collection <p></p><p></p><p> This is the 13th day of the reference book program: The program is a program for each view Control page to specify a small dot, and use the white origin to display the current page, click on the small dot above the page control control to guide the program to page .... However, this paging means is inconvenient, so the page control is best to slide the pages, then do a swipe and click on the dots can be implemented to flip (Uiscrollview and Uipagecontrol) demo. </p><p></p><p> reference: Http://www.gowhich.com/blog/522</p><p><span style= " font-size:18px; " ><span style= "FONT-SIZE:12PX;" > Reference:http://blog.csdn.net/a351945755/article/details/8290552</span></span></p><p> <span style= "FONT-SIZE:18PX;" ><span style= "FONT-SIZE:12PX;" ><span style= "FONT-SIZE:12PX;" ><span style= "FONT-SIZE:18PX;" ><span style= "FONT-SIZE:12PX;" ><span style= "FONT-SIZE:18PX;" ><span style= "FONT-SIZE:12PX;" > Reference: </SPAN></SPAN≫</span></span>http://www.cnblogs.com/wendingding/p/3754210.html</span></span></ Span></p><p><span style= "Background-color:rgb (255,255,255)" ><span style= "font-size:18px;" ><span style= "FONT-SIZE:12PX;" ><span style= "FONT-SIZE:12PX;" ></span></span></span></span></p><pre class= "Brush:cpp;toolbar:false" > <span style= "color: #009900;" ><span style= "FONT-SIZE:18PX;" ><span style= "FONT-SIZE:12PX;" > Reference:</span></span>http://blog.sina.com.cn/s/blog_87a824440101a0p5.html</span>
Simple application of 1.UIScrollView scrolling view and Uipagecontrol pagination control
Create a simple storyboard, add a uiviewcontoller inside, add a pagecontrol and a scrollview to the view, and make a link.
. h file
@property (Strong, nonatomic) Iboutlet Uiscrollview *pagescroll;//Create an object for a scroll control @property (strong, nonatomic) Iboutlet Uipagecontrol *pagecontrol;//Create a small Dot control object
Also add an array variable that stores the image you want to show
@property (Strong, Nonatomic) Nsarray *photolist;-(ibaction) Changepage: (ID) sender;//How to create a human-machine interaction, listening to the value of page control Change Event
Also to join
Uiscrollviewdelegate
Agent
After the basic work is done, we begin our process of achieving
The initialization works as follows:
- (void) viewdidload//the method { [super viewdidload];//default statement called when the view loading is complete// do any additional setup after loading the view. NSString * img1 = [[nsbundle mainbundle] pathforresource:@ "Bg_welcome1" oftype:@ "PNG"]; nsstring *img2 = [[nsbundle mainbundle] pathforresource:@ "Bg_welcome2" oftype:@ "PNG"]; nsstring *img3 = [[nsbundle mainbundle] pathforresource:@ "Bg_welcome3" oftype:@ "PNG"]; //nsbundle is actually a directory class that contains the resources that are used in the program, the images, sounds, compiled code, NIB files, and so on. //For Mainbandel: In the Finder, an application looks no different from other files, but in fact it is a directory containing nib files, compiled code, and other resources, and we put this The directory is called the Mainbandel of the program. So [NSBundle Mainbundle] is to get the directory of this project, and the "Pathforresource: File name OfType: Format" method is to obtain the corresponding file address. //Integrated: Gets the address of three images and assigns them to three string objects. _photolist = [[nsarray alloc] initwithobjects: [UIImage imagewithcontentsoffile:img1], [UIImage imageWithContentsOfFile:img2], [uiimage imagewithcontentsoffile: img3], , nil]; The "Imagewithcontentsoffile: Address" method is to load the picture of the address on the UIImage object and then make up an array of these objects. (the first three elements of the array)//for the fourth array element, it invokes the method of the program itself to take an array element, and then to talk about it. //Until now, when the view is loaded, an array of UIImage objects is generated. nsinteger pagecount = [_photolist count];//creates a shaping object that stores the number of elements (pictures) inside an array. _pagecontrol.currentpage = 0; Set the first page to the current page _pagecontrol.numberofpages = pagecount; Set total PageCount pages//belowThe code involves a type of OC inside CGRect _pagescroll.frame = cgrectmake (0.0, Frame is the view in the parent view so far and the size. 0.0,// CGRectMake definition (x,y,width,height) 320.0, 400.0); _pagescroll.delegate = self; Sets the proxy for the Uiscrollview to its object itself. for (nsinteger i=0;i<pagecount;i++)//Give eachPage Setup Pictures { cgrect frame; Create a CGRect object frame.origin.x = _ pagescroll.frame.size.width * i; frame.origin.y = 0; frame.size = _pageScroll.frame.size; This code represents the size of the front pagescroll as a template, the ordinate constant, the horizontal axis of the right to move the size of the pagescroll, equivalent to the same// Several pictures are stitched together, the first picture of the horizontal ordinate is 0, because 0*width = 0; Here again a new knowledge point: Uiimageview's Contentmode Property //This property is used to set the display of the image, such as the local middlegame whether the right display zoom and other references: http://blog.csdn.net/ sqc3375177/article/details/17415635 //uiviewcontentmodescaleaspectfill effect is that the proportions of the picture remain the same, However, the content that fills the entire imageview may show only a portion, and some of it will not appear. //Because the operation of these images is only saved in ImageView form from project, and no specification is made for the size of the picture, so now the Uiimageview frame is regulated, and the control //property is Fill uiimageview with picture proportions
Uiimageview *pageview;
Pageview.frame = frame;
Pageview.contentmode = Uiviewcontentmodescaleaspectfill;
PageView = [[Uiimageview alloc] initwithimage:[_photolist objectatindex:i]];//Get the Picture object inside the array (picture of the Uiimageview object) [_pages Croll Addsubview:pageview];//addsubview method adds Uiimageview to Uiscrollview above}}-(void) Viewwillappear: (BOOL) Animated// System default method, the view will be called when the {//code below is to set the size of the Uiscrollview to several uiimageview stitching into the size after cgsize pagescrollviewsize = _pagescroll.frame . size; _pagescroll.contentsize = Cgsizemake (Pagescrollviewsize.width * _photolist.count, pagescrollviewsize.height); Contentsize is an area where uiscrollview can scroll. The size of the Uiscrollview is actually the size of the frame, the upper layer fixed motionless, the display changes, by the lower scroll to control. The size of the lower-level scrolling area is controlled by the contentsize. [Super Viewwillappear]; }
How to monitor Pagecontrol
-(Ibaction) Changepage: (ID) Sender {//Update scroll view to the correct page cgrect frame; frame.origin.x = _pagescroll.frame.size.width * _pagecontrol.currentpage;//_pagecontrol.currentpage = 0 (previously defined) FRAME.ORIGIN.Y = 0; Frame.size = _pagescroll.frame.size; [_pagescroll scrollrecttovisible:frame animated:yes];//This method is to switch the picture, the picture will be switched to the specified Frame,yes to open the animation effect, is not so blunt when the switch}
Method of view scrolling
-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{cgfloat pagewidth = _pagescroll.frame.size.width;// CGFloat is CGRect's floating-point value width//When scrolling over 50% of the page width, switch to the new page int page = Floor ((_pagescroll.contentoffset.x + PAGEWIDTH/2) /pagewidth);//floor is rounded down _pagecontrol.currentpage = page;}
2. My own program
<span style= "color: #6600CC;" >// viewcontroller.h// 13//// Created by Liddy on 15-7-29.// Copyright (c) 2015 Liddy. All rights reserved.//#import <UIKit/UIKit.h> @interface viewcontroller:uiviewcontroller< uiscrollviewdelegate>{ iboutlet Uipagecontrol *pagecontrol; Iboutlet Uiscrollview *scrollview;} @property Uipagecontrol *pagecontrol; @property (strong,nonatomic) Uiscrollview *scrollview; @property Nsarray * photoarray;-(ibaction) pagechange;//here Pagechange and the above Pagecontrol are connected to the Uipagecontrol, here can be connected two times, because one is a property, one is the method @end/ / viewcontroller.m// 13//// Created by Liddy on 15-7-29.// Copyright (c) 2015 Liddy. All rights reserved./* ideas: Through the combination of storyboard and code to achieve Uipagecontrol and uiscrollview two ways to turn the page It is necessary to create Uipagecontrol and Uiscrollview objects in the form of Iboutlet, and to add controls for both objects in storyboard (although the program has a uisrollview size set, But in storyboard inside still want to adjust the Uisrollview space to the corresponding size, otherwise with the code written still does not match) </span>
Add a picture to a project, whatever folder you want to add to it, save the picture in an array, manipulate the picture with an array
<span style= "color: #006600;" > through the loop to add the image inside the array to Uiscrollview to implement two ways to turn the page, one is ibaction, one is to implement the agent specific look at the following code */#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller@synthesize Photoarray,scrollview,pagecontrol; -(void) viewdidload {[Super viewdidload]; Scrollview.delegate =self; Set the agent for ScrollView to self scrollview.pagingenabled =yes; Pagingenabled-scrollview Properties-Determines whether full-page flipping is enabled (default is no, so the page flips slowly when it slides, so it tends to turn on) Scrollview.showshorizontalscrollindicator = NO; Scrollview.showsverticalscrollindicator = NO; These two properties show that the horizontal scroll indicator shows the vertical scroll indicator does not close and the progress bar is displayed nsstring *img1 = [[NSBundle mainbundle] pathforresource:@ "one" oftype:@ "PNG"] ; NSString *img2 = [[NSBundle Mainbundle] pathforresource:@ "+" oftype:@ "png"]; NSString *IMG3 = [[NSBundle Mainbundle] pathforresource:@ "to" oftype:@ "PNG"]; NSString *IMG4 = [[NSBundle mainbundle] pathforresource:@ "All" oftype:@ "PNG"]; When you add a slide image to the inside of a folder, use the [[Nsbundel Mainbundel] Pathforresource:oftype:] method Gets the address of the picture and assigns the value to the string object Photoarray = [Nsarray arraywithobjects: [UIImage IMAGEWITHCONTENTSOFFILE:IMG1], [UIImage Imagewithcontentsoffile:img2], [UIImage imagewit HCONTENTSOFFILE:IMG3], [UIImage Imagewithcontentsoffile:img4],nil]; Using the [UIImage imagewithcontentsoffile:string] method, the image object is obtained by the address, the image object is added to the Photoarray array, so the image can also be added to the array inside//here to say, Uiimageview and UIImage were always mixed up, Uiimageview is a view control that can be used to store uiimage (Image Class) objects Nsinteger PageCount = [Photoarray count]; The number of images in the array is set up individually for easy operation pagecontrol.numberofpages = PageCount; Set the number of small white dots Uipagecontrol (pages) pagecontrol.currentpage = 0; Set the current page to the first page scrollview.frame = CGRectMake (0, 0, 320, 443); Set interface coordinates and length width (display interface) Scrollview.contentsize = Cgsizemake (scrollView.frame.size.width * pagecount, 0);//Set range sliding plug-in The display interface size and the sliding size are two concepts! The display interface size is the size of each picture, and behind the sliding range, is the size of all the pictures are tiled for (nsinteger i = 0; i<pagecount; i++) {//through forThe loop is implemented to add each picture to Uiscrollview above cgrect frame; frame.origin.x = ScrollView.frame.size.width * i; FRAME.ORIGIN.Y = 0; Frame.size = scrollView.frame.size; Through the loop to achieve the corresponding frame size of each picture unchanged, the purpose of the horizontal axis change Uiimageview *imagedemo; Imagedemo = [[Uiimageview alloc] Initwithimage:[photoarray objectatindex:i]]; Take the corresponding picture out to Imagedemo, then add the attribute to Imagedemo Imagedemo.contentmode = uiviewcontentmodescaleaspectfill;// The picture is completely filled in imagedemo imagedemo.frame = frame; For Uiimageview properties and sizes, be sure to adjust the Uiimageview object before it is assigned, otherwise the displayed view does not match the target view. [ScrollView addsubview:imagedemo];//Add Imagedemo to Uiscrollview View}}//uipagecontrol Method Implementation page-(ibaction) pagechange{/ /cgrect frame;//FRAME.ORIGIN.Y = 0;//frame.origin.x = self.scrollView.frame.size.width * PAGECONTROL.CURRENTPA ge;//frame.size = self.scrollview.frame.size;//[Self.scrollview scrollrecttovisible:frame Animated:YES]; The above comments in the method of my Xcode after running the page, can only use the following method instead of [scrollView Setcontentoffset:cgpointmake (self.scrollView.frame.size.width * pagecontrol.currentpage, 0) Animated:yes]; Calling Uiscrollview's Setcontentoffset (Setting the content offset, changing the coordinates) animated (animation) makes the offset smoother and does not appear stiff}-(void) Scrollviewdidscroll: ( Uiscrollview *) scrollview{cgfloat pagewidth = self.scrollView.frame.size.width; Gets the width of the display view int page = Floor ((self.scrollview.contentoffset.x + pagewidth/2)/pagewidth);//sliding over half of the view to trigger page flipping Pagecontrol . currentpage = page; An algorithm for offset}-(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end </span>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Program Log--ios "page control" program