The effect is as follows:
ViewController.h
1 #import <UIKit/UIKit.h>23@interface viewcontroller: Uiviewcontroller4@end
Viewcontroller.m
1 #import "ViewController.h"2 #import "KMLabelViewController.h"3 4 @interfaceViewcontroller ()5- (void) Layoutui;6 @end7 8 @implementationViewcontroller9 #defineKnumberofpages 3Ten One- (void) Viewdidload { A [Super Viewdidload]; - - [self layoutui]; the } - -- (void) didreceivememorywarning { - [Super didreceivememorywarning]; + //Dispose of any resources the can be recreated. - } + A- (void) Layoutui { atCGFloat viewwidth =Self.view.frame.size.width; -CGFloat viewheight =Self.view.frame.size.height; - -Uiscrollview *scrvcustom =[[Uiscrollview alloc] initWithFrame:self.view.bounds]; - //to be able to roll horizontally, set the horizontal length of the scrolling view scrvcustom content -Scrvcustom.contentsize = Cgsizemake (Viewwidth *knumberofpages, viewheight); in //sets whether to roll over pages; default value is no -scrvcustom.pagingenabled =YES; to //sets whether the horizontal and vertical scroll bars are displayed; The default is Yes +Scrvcustom.showshorizontalscrollindicator =YES; -Scrvcustom.showsverticalscrollindicator =NO; the //sets whether to allow scrolling to the top; The default value is Yes *Scrvcustom.scrollstotop =NO; $ Panax Notoginseng //set the color of the scroll bar - //uiscrollviewindicatorstyledefault (white box surrounds black lines, most of the background applies); Default Value the //Uiscrollviewindicatorstyleblack (black bar) + //uiscrollviewindicatorstylewhite (white bar) AScrvcustom.indicatorstyle =Uiscrollviewindicatorstyledefault; the + for(Nsinteger i=0; i<knumberofpages; i++) { -Kmlabelviewcontroller *lblviewcontroller =[[Kmlabelviewcontroller alloc] initwithnumber:i]; $LblViewController.view.frame = CGRectMake (Viewwidth * I,0, Viewwidth, viewheight); $ [Scrvcustom AddSubview:lblViewController.view]; - } - [Self.view Addsubview:scrvcustom]; the } - Wuyi @end
KMLabelViewController.h
1 #import <UIKit/UIKit.h>23@interface kmlabelviewcontroller: Uiviewcontroller4 -(ID) initwithnumber: (nsinteger) number; 5 6 @end
Kmlabelviewcontroller.m
1 #import "KMLabelViewController.h"2 3 @interfaceKmlabelviewcontroller ()4 @end5 6 @implementationKmlabelviewcontroller7 8- (void) Viewdidload {9 [Super Viewdidload];Ten } One A- (void) didreceivememorywarning { - [Super didreceivememorywarning]; - //Dispose of any resources the can be recreated. the } - -- (ID) Initwithnumber: (nsinteger) Number { - if(self =[Super Init]) { +UILabel *lblcustom = [[UILabel alloc] Initwithframe:cgrectinset (Self.view.bounds,0,0)]; -Lblcustom.text = [NSString stringWithFormat:@"%ld", (Long) number]; +Lblcustom.textalignment =Nstextalignmentcenter; ALblcustom.textcolor = [Uicolor performselector:nsselectorfromstring (number%2==1?@"Whitecolor":@"Blackcolor")]; atLblcustom.backgroundcolor = [Uicolor performselector:nsselectorfromstring (number%2==1?@"Blackcolor":@"Whitecolor")]; -Lblcustom.font = [Uifont boldsystemfontofsize: -]; - [Self.view Addsubview:lblcustom]; - } - returnSelf ; - } in - @end
106 set the color of the scroll bar (extended knowledge: Set the scrollbar as a paging form)