Let's take a look at our results.
This kind of image switch often appears on the homepage of the Mall or forum to showAnalysis
Here I use the Uiscrollview and pagecontroll to achieve a kind of tile navigation, involving two kinds of operations: 1 Click Pagecontrol 2 page change conversion pagecontroll
Realize
#import "ViewController.h" #define WEIGHT [UIScreen mainscreen].bounds.size.width#define HEIGHT [UIScreen mainscreen]. Bounds.size.height@interface Viewcontroller () <UIScrollViewDelegate> @end @implementation Viewcontroller@synthesize Topdisplayscroller; @synthesize page;-(void) viewdidload {[Super viewdidload]; [Self createtopindex];} -(void) didreceivememorywarning {[Super didreceivememorywarning];} #pragma mark-Create a slide view above the home/* Principle: Create a sub-page, ScrollView, create a floating pagecontroller on top ———— slide show */-(void) createtopindex{TOPD Isplayscroller.contentsize=cgsizemake (weight*5, topDisplayScroller.frame.size.height); topdisplayscroller.pagingenabled=yes;//allow page slip for (int i=0; i<5; i++) {Uiimageview *imagepage=[[uiimagev Iew Alloc]initwithframe:cgrectmake (weight*i, 0, WEIGHT, topDisplayScroller.frame.size.height)]; Imagepage.image=[uiimage imagenamed:@ "1"]; [Topdisplayscroller Addsubview:imagepage]; }/* * Note: Add Pagecontrol, but cannot be added to Scroller's content viewOn, why? Since added to the above to go after Pagecontrol will slide * * Page=[[uipagecontrol alloc]initwithframe:cgrectmake (WEIGHT/6, 20+topdisplayscroller. FRAME.SIZE.HEIGHT*2/3, 50, 20)]; page.numberofpages=5; Page.currentpageindicatortintcolor=[uicolor Orangecolor]; Page.pageindicatortintcolor=[uicolor Whitecolor]; [Self.page addtarget:self Action: @selector (changepage:) forcontrolevents:uicontroleventvaluechanged]; [Self.view addsubview:page];} /* Function: Slide scroller, drive Pagecontrol */-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{cgpoint offset= Scrollview.contentoffset; Self.page.currentpage=offset.x/weight;} /* Function: Click Pagecontroll, Animation */-(void) Changepage: (ID) sender{[UIView animatewithduration:0.3f animations:^{Nsint Eger whichpage = self.page.currentPage; Topdisplayscroller.contentoffset = Cgpointmake (weight* whichpage, 0.0f); }];} @end
Source code: Https://git.oschina.net/zhengaoxing/TopIndex
This article original, reproduced please indicate the source:http://blog.csdn.net/zhenggaoxing/article/details/43965373
The implementation of the IOS picture toggle Display