iOS development-Automatic carousel diagram creation

Source: Internet
Author: User

Here is the OC version, which is simply recorded below:

The specific code is as follows:

1, prepare

#define FRAME [[UIScreen mainscreen] bounds]#define WIDTH  FRAME.size.width#define HEIGHT FRAME.size.height

2, the concrete realization

 //ScrollView Add-on_bigscrollview = [[Uiscrollview alloc]initwithframe:cgrectmake (0, -, WIDTH, HEIGHT)]; _bigscrollview.showshorizontalscrollindicator=NO; _bigscrollview.contentsize= Cgsizemake (WIDTH *6,0); _bigscrollview.pagingenabled=YES; _bigscrollview.bounces=NO; _bigscrollview.Delegate=Self ;        [Self.view Addsubview:_bigscrollview]; //Add a picture content     for(inti =0; i<6; i++) {Uiimageview*imageview = [[Uiimageview alloc]initwithframe:cgrectmake (i *width,0, WIDTH, HEIGHT)]; Imageview.image= [UIImage imagenamed:[nsstring stringWithFormat:@"%d.jpg", I]];    [_bigscrollview Addsubview:imageview]; }        //creation of Pagecontrol_pagecontrol = [[Uipagecontrol alloc] Initwithframe:cgrectmake (0,0, WIDTH, +)] ; _pagecontrol.center=Cgpointmake (_bigscrollview.center.x, _BIGSCROLLVIEW.CENTER.Y); _pagecontrol.numberofpages=6; _pagecontrol.currentpage=0; _pagecontrol.pageindicatortintcolor=[Uicolor Bluecolor]; _pagecontrol.currentpageindicatortintcolor=[Uicolor Redcolor];    [Self.view Addsubview:_pagecontrol];        [_pagecontrol addtarget:self Action: @selector (Pagecontrollerclick) forcontrolevents:uicontroleventvaluechanged]; //Creation of Timers_timer = [Nstimer scheduledtimerwithtimeinterval:2Target:self selector: @selector (OnTimer) Userinfo:nil Repeats:yes];

3, the implementation of the response method

-(void) pagecontrollerclick{[_bigscrollview setcontentoffset:cgpointmake (_pagecontrol.currentpage* the,0) Animated:yes];}//when the ScrollView starts to slide manually- (void) Scrollviewwillbegindragging: (Uiscrollview *) scrollview{[_timer setfiredate:[nsdate distantfuture];}//add a delay method to ScrollView- (void) Scrollviewdidenddecelerating: (Uiscrollview *) scrollview{_pagecontrol.currentpage= _bigscrollview.contentoffset.x/WIDTH; [Self performselector: @selector (dispast) withobject:nil Afterdelay:2];//Delay Method    }//Start Timer-(void) dispast{[_timer setfiredate:[nsdate distantpast];}Static intCount=1;//the specific response method of the timer-(void) ontimer{_pagecontrol.currentpage+=count; if(_pagecontrol.currentpage==_pagecontrol.numberofpages-1|| _pagecontrol.currentpage==0) {Count=-count;    }; [_bigscrollview setcontentoffset:cgpointmake (_pagecontrol.currentpage*width,0) Animated:yes]; }

No, it's just a record!

iOS development-Automatic carousel diagram creation

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.