The implementation of the IOS picture toggle Display

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.