106 set the color of the scroll bar (extended knowledge: Set the scrollbar as a paging form)

Source: Internet
Author: User

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)

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.