103 adding or removing the number of pages in a screen

Source: Internet
Author: User

The effect is as follows:

ViewController.h

1 #import <UIKit/UIKit.h>23@interface  viewcontroller: Uiviewcontroller4 @property (Strong, Nonatomic) Uipagecontrol *Pageccustom; 5 6 @end

Viewcontroller.m

1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4- (void) Layoutui;5- (void) loadnavigation;6- (void) Pagecontroldidchange: (Uipagecontrol *) sender;7- (void) Adddidpush: (Uibarbuttonitem *) sender;8- (void) Deldidpush: (Uibarbuttonitem *) sender;9 @endTen  One @implementationViewcontroller A  -- (void) Viewdidload { - [Super Viewdidload]; the      - [self layoutui]; - } -  +- (void) didreceivememorywarning { - [Super didreceivememorywarning]; +     //Dispose of any resources the can be recreated. A } at  -- (void) Viewwillappear: (BOOL) Animated { - [Super viewwillappear:animated]; - [Self.navigationcontroller setnavigationbarhidden:no animated:animated]; - [Self.navigationcontroller settoolbarhidden:no animated:animated]; - } in  -- (void) Layoutui { to [self loadnavigation]; +      -_pageccustom = [[Uipagecontrol alloc] Initwithframe:cgrectmake (0,0, the, -)]; the_pageccustom.center =Self.view.center; *_pageccustom.backgroundcolor =[Uicolor Browncolor]; $_pageccustom.numberofpages =3;Panax Notoginseng_pageccustom.currentpage =0; - [_pageccustom addtarget:self the Action: @selector (pagecontroldidchange:) + forcontrolevents:uicontroleventvaluechanged]; A [Self.view Addsubview:_pageccustom]; the } +  -- (void) loadnavigation { $Self.navigationItem.title =@"Add or remove the number of pages in a screen"; $Self.view.backgroundColor =[Uicolor Whitecolor]; -Uibarbuttonitem *barbtnbaradd = -[[Uibarbuttonitem alloc] Initwithtitle:@"Add a new page" the Style:uibarbuttonitemstyledone - target:selfWuyi Action: @selector (Adddidpush:)]; theUibarbuttonitem *barbtndel = -[[Uibarbuttonitem alloc] Initwithtitle:@"Delete old page" Wu Style:uibarbuttonitemstyledone - target:self About Action: @selector (Deldidpush:)]; $ [self Settoolbaritems:@[barbtnbaradd, Barbtndel]]; - } -- (void) Pagecontroldidchange: (Uipagecontrol *) Sender { -Uialertview *alert = [[Uialertview alloc] Initwithtitle:@"Prompt Information" AMessage:[nsstring stringWithFormat:@"currentpage=%ld", (Long) Sender.currentpage] +                                                    Delegate: Self the Cancelbuttontitle:nil -Otherbuttontitles:@"Determine", nil]; $ [alert show]; the } the  the- (void) Adddidpush: (Uibarbuttonitem *) Sender { the     if(_pageccustom.numberofpages <Ten) { -_pageccustom.numberofpages++; in     } the } the  About- (void) Deldidpush: (Uibarbuttonitem *) Sender { the     if(_pageccustom.numberofpages >1) { the_pageccustom.numberofpages--; the [self pagecontroldidchange:_pageccustom]; +     } - } the Bayi @end

AppDelegate.h

1 #import <UIKit/UIKit.h>23@interface Appdelegate:uiresponder < Uiapplicationdelegate>4 @property (Strong, Nonatomic) UIWindow *window; 5 @property (Strong, Nonatomic) Uinavigationcontroller *Navigationcontroller; 6 7 @end

Appdelegate.m

1 #import "AppDelegate.h"2 #import "ViewController.h"3 4 @interfaceappdelegate ()5 @end6 7 @implementationappdelegate8 9-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Ten_window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; OneViewcontroller *viewcontroller =[[Viewcontroller alloc] init]; A_navigationcontroller =[[Uinavigationcontroller alloc] initwithrootviewcontroller:viewcontroller]; -_window.rootviewcontroller =_navigationcontroller; -     //[_window Addsubview:_navigationcontroller.view];//when _window.rootviewcontroller is associated, this sentence is optional the [_window makekeyandvisible]; -     returnYES; - } -  +- (void) Applicationwillresignactive: (UIApplication *) Application { - } +  A- (void) Applicationdidenterbackground: (UIApplication *) Application { at } -  -- (void) Applicationwillenterforeground: (UIApplication *) Application { - } -  -- (void) Applicationdidbecomeactive: (UIApplication *) Application { in } -  to- (void) Applicationwillterminate: (UIApplication *) Application { + } -  the @end

103 to add or remove the number of pages in the screen

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.