Scrollview Example 2

Source: Internet
Author: User

Code:

# Import "rootviewcontroller. H "@ implementation rootviewcontroller @ synthesize scrollview;-(void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view. int pagecount = 3; scrollview = [[uiscrollview alloc] initwithframe: [uiscreen mainscreen] applicationframe]; [self. view addsubview: scrollview]; scrollview. backgroundcolor = [uicolor redcolor]; scrollview. scrollenabled = no; scrollview. contentsize = cgsizemake (scrollview. frame. size. width * pagecount, scrollview. frame. size. height); scrollview. pagingenabled = yes; scrollview. showshorizontalscrollindicator = yes; scrollview. delegate = self; cgrect rect = [[uiscreen mainscreen] bounds]; nsarray * Colors = [nsarray arraywithobjects: [uicolor yellowcolor], [uicolor bluecolor], [uicolor purplecolor], nil]; for (INT I = 0; I <pagecount; I ++) {cgrect arect = cgrectmake (rect. origin. X + (I * rect. size. width), rect. origin. y, rect. size. width, rect. size. height); uiview * view1 = [[uiview alloc] initwithframe: arect]; view1.backgroundcolor = colors [I]; [scrollview addsubview: view1];} [self movetopage: 3];} -(void) movetopage :( INT) index {index --; cgrect rect = [uiscreen mainscreen] bounds]; cgpoint point = cgpointmake (rect. size. width * index, 0); [scrollview setcontentoffset: Point];}-(void) scrollviewdidenddecelerating :( uiscrollview *) scrollview {// call int Index = [self getpageindex: scrollview]; nslog (@ "Index = % d", index);}-(INT) getpageindex :( uiscrollview *) scrollview {return FABS (scrollview. contentoffset. x)/scrollview. frame. size. width;} @ end

 

Scrollview Example 2

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.