Cat Share, must boutique
Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243
One: Effect
Behind is the Xcode console.
Two: Code Viewcontroller
#import "ViewController.h" #import "ColorsViewController.h" @interface viewcontroller () <colorsviewcontrollerdelegate, Uipopovercontrollerdelegate>- (ibaction) ButtonClick: (UIButton*) btn;@property(nonatomic,Weak)UIButton*colorbutton;@property(nonatomic,Strong)Uipopovercontroller*popover;@property(Weak,nonatomic)Iboutlet UIButton*greenbutton;-(ibaction) Greenbuttonclick;@end @implementation viewcontroller - (void) Viewdidload {[SuperViewdidload];} - (ibaction) Greenbuttonclick {NSLog(@"Greenbuttonclick");} - (ibaction) ButtonClick: (UIButton*) BTN {//0. ContentColorsviewcontroller *colors = [[Colorsviewcontroller alloc] init]; Colors. Delegate= Self;//1. Create Self. PopOver= [[UipopovercontrollerAlloc] initwithcontentviewcontroller:colors]; Self. PopOver. Delegate= Self;//2. Display//[Self.popover Presentpopoverfromrect:cgrectmake (InView:btn.superview) Permittedarrowdirections:uipopoverarrowdirectionany Animated:yes];[ Self. PopOverPresentpopoverfromrect:cgrectmake (924,668, -, -) inview:btn. SuperviewPermittedarrowdirections:uipopoverarrowdirectionany Animated:YES];//[Self.popover presentPopoverFromRect:btn.bounds inview:btn permittedarrowdirections: Uipopoverarrowdirectionany Animated:yes];//[Self.popover presentPopoverFromRect:btn.frame inView:btn.superview permittedarrowdirections: Uipopoverarrowdirectionany Animated:yes]; //3. Set where controls can still interact with the user when the PopOver is displayed Self. PopOver. Passthroughviews= @[ Self. Greenbutton]; Self. Colorbutton= BTN;}#pragma mark-color selector agent- (void) Colorsviewcontroller: (Colorsviewcontroller *) VC Didselectcolor: (Uicolor*) color{ Self. Colorbutton. BackgroundColor= color;//Close PopOver[ Self. PopOverDismisspopoveranimated:YES];}#pragma agent for Mark-popover- (void) Popovercontrollerdiddismisspopover: (Uipopovercontroller*) popovercontroller{NSLog(@"PopOver destroyed.");}@end
Colorsviewcontroller
#import <UIKit/UIKit.h> @class colorsviewcontroller; @protocol colorsviewcontrollerdelegate <nsobject>@optional- (void) Colorsviewcontroller: (Colorsviewcontroller *) VC Didselectcolor: (Uicolor*) color;@end @interface colorsviewcontroller : uitableviewcontroller @property(nonatomic,Weak)ID<ColorsViewControllerDelegate> delegate;@end
#import "ColorsViewController.h" @interface colorsviewcontroller ()@end @implementation colorsviewcontroller - (void) Viewdidload {[SuperViewdidload]; Self. TableView. Separatorstyle= Uitableviewcellseparatorstylenone;} - (void) Didreceivememorywarning {[SuperDidreceivememorywarning];//Dispose of any resources, can be recreated.}#pragma mark-table view data source- (Nsinteger) TableView: (UITableView*) TableView numberofrowsinsection: (Nsinteger) Section {return -;} - (UITableViewCell*) TableView: (UITableView*) TableView Cellforrowatindexpath: (Nsindexpath*) indexpath{Static NSString*id = @"Cell";UITableViewCell*cell = [TableView dequeuereusablecellwithidentifier:id];if(!cell) {cell = [[UITableViewCellAlloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:id]; Cell. Selectionstyle= Uitableviewcellselectionstylenone; } cell. BackgroundColor= [UicolorColorwithred:arc4random_uniform (255)/255.0Green:arc4random_uniform (255)/255.0Blue:arc4random_uniform (255)/255.0Alpha1.0];returnCell;} - (void) TableView: (UITableView*) TableView Didselectrowatindexpath: (Nsindexpath*) indexpath{if([ Self. DelegateRespondstoselector:@selector(Colorsviewcontroller:didselectcolor:)]) {Uicolor*color = [TableView Cellforrowatindexpath:indexpath]. BackgroundColor; [ Self. DelegateColorsviewcontroller: SelfDidselectcolor:color]; }}@end
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Cat learns iOS ipad Development popover Palette App _popover show other controls can still interact