[IOS Uiscrollview+pagecontrol] Information display banner

Source: Internet
Author: User

ScrollViewController.h

#import <UIKit/UIKit.h>@interface scrollviewcontroller:uiviewcontroller< Uiscrollviewdelegate,uipageviewcontrollerdelegate>{    *_scrollview;    Uipagecontrol*_pagecontrol;} @end

Scrollviewcontroller.m

#import "ScrollViewController.h"@interfaceScrollviewcontroller ()@end@implementationScrollviewcontroller- (ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{ Self=[Super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if(self) {}returnSelf ;}- (void) viewdidload{[Super Viewdidload]; //set the overall touch and display area of the ScrollView//Note that the width is not greater than 320X480//Otherwise, there will be a situation where you cannot scroll_scrollview = [[[Uiscrollview alloc] Initwithframe:cgrectmake (0,0, the, -)] [autorelease]; //set the area of ScrollView scrolling content//It is typically a display area that needs to be larger than Scrollerview.//so it's necessary to roll it in the Scrollerview.[_scrollview Setcontentsize:cgsizemake ( the*5, -)]; //turn on the scrolling paging function, if you do not need this feature to turn off[_scrollview Setpagingenabled:yes]; //Hide Horizontal and vertical scroll bars[_scrollview Setshowsverticalscrollindicator:no];        [_scrollview Setshowshorizontalscrollindicator:no]; //The overall event of Agent ScrollView in this class[_scrollview setdelegate:self]; //If you open the horizontal or vertical scroll bar, you can set the style of the scroll bar here//Uiscrollviewindicatorstyledefault, default style//Uiscrollviewindicatorstyleblack, black style//Uiscrollviewindicatorstylewhite White style//[_scrollview Setindicatorstyle:uiscrollviewindicatorstyleblack]          for(inti =0; i<5; i++)    {                //here, add a picture and a button to each of the ScrollView .Uiimageview *imageview= [[[Uiimageview alloc] Initwithframe:cgrectmake (i * the,0, the, -)] [autorelease]; [ImageView setimage:[uiimage imagenamed:@"Image.png"]]; UIButton* Button =[UIButton Buttonwithtype:uibuttontyperoundedrect]; Button.frame= CGRectMake (i * the,Ten, -, -); [Button Settitle:@"This is a button"Forstate:uicontrolstatenormal];                [Button addtarget:self action: @selector (ButtonClick) forcontrolevents:uicontroleventtouchupinside]; //Add the view that needs to be displayed on each page into the Scrollerview[_scrollview Addsubview:imageview];    [_scrollview Addsubview:button]; }    //The whole then displays the Scrollerview in the window[Self.view Addsubview:_scrollview]; //page Control Gadget//It draws a small dot at the bottom of the current display page_pagecontrol = [[[Uipagecontrol alloc] Initwithframe:cgrectmake (0, -, Self.view.frame.size.width, -)]autorelease]; //set the number of pages[_pagecontrol setnumberofpages:5]; //whether the monitoring page has changed[_pagecontrol addtarget:self Action: @selector (changepage:) forcontrolevents:uicontroleventvaluechanged];    [Self.view Addsubview:_pagecontrol]; }- (void) Changepage: (ID) sender{//get the ID of the current page//int page = [sender currentpage]; //write the code you need to execute here//......}//after the finger leaves the screen scrollview will continue to scroll for a period of time only to stop- (void) Scrollviewdidenddecelerating: (Uiscrollview *) scrollview{NSLog (@"called when the buffered scroll ends completely after scrolling");}-(void) Scrollviewwillbegindecelerating: (Uiscrollview *) scrollview{NSLog (@"called when the buffer scroll starts after scrolling is finished");}-(void) Scrollviewdidscroll: (uiscrollview*) scrollview{//called when the page scrolls, setting the ID of the current page[_pagecontrol Setcurrentpage:fabs (scrollview.contentoffset.x/Self.view.frame.size.width)]; NSLog (@"x-axis coordinates%f in view scrolling", Scrollview.contentoffset.x); NSLog (@"x-axis coordinates%f in view scrolling", Scrollview.contentoffset.y);}-(void) Scrollviewwillbegindragging: (uiscrollview*) scrollview{NSLog (@"scrolling View starts scrolling, it only calls once");}-(void) Scrollviewdidenddragging: (uiscrollview*) ScrollView willdecelerate: (BOOL) decelerate{NSLog (@"scrolling View ends scrolling, it is only called once");}-(void) buttonclick{NSLog (@"button clicked on the");}- (void) viewdidunload{[Super Viewdidunload];}-(BOOL) shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation{return(Interfaceorientation = =uiinterfaceorientationportrait);}@end

[IOS Uiscrollview+pagecontrol] Information display banner

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.