Cat Share, must boutique
Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243
One: Effect
Two: Packaged tool strips NYComposeToolbar.h
With Proxy method
#import <UIKit/UIKit.h> typedef enum{Nycomposetoolbarbuttontypecamera,//PhotoNycomposetoolbarbuttontypepicture,//albumsNycomposetoolbarbuttontypemention,// @Nycomposetoolbarbuttontypetrend,// #Nycomposetoolbarbuttontypeemotion//Emoticons} Nycomposetoolbarbuttontype; @class nycomposetoolbar; @protocol nycomposetoolbardelegate <nsobject>@optional- (void) Composetoolbar: (Nycomposetoolbar *) toolbar Didclickbutton: (Nycomposetoolbarbuttontype) ButtonType;@end @interface nycomposetoolbar : UIView @property(nonatomic,Weak)ID<NYComposeToolbarDelegate> delegate;@end
Nycomposetoolbar.m
////NYCOMPOSETOOLBAR.M//Black horse Weibo 2////Created by Apple on 14-10-20.//Copyright (c) 2014 Heima. All rights reserved.//#import "NYComposeToolbar.h" @implementation nycomposetoolbar - (ID) initWithFrame: (CGRect) frame{ Self= [SuperInitwithframe:frame];if( Self) { Self. BackgroundColor= [Uicolorcolorwithpatternimage:[UIImageimagenamed:@"Compose_toolbar_background"]];//Initialize button[ Selfsetupbtn:@"Compose_camerabutton_background"highimage:@"compose_camerabutton_background_highlighted"Type:nycomposetoolbarbuttontypecamera]; [ Selfsetupbtn:@"Compose_toolbar_picture"highimage:@"compose_toolbar_picture_highlighted"Type:nycomposetoolbarbuttontypepicture]; [ Selfsetupbtn:@"Compose_mentionbutton_background"highimage:@"compose_mentionbutton_background_highlighted"Type:nycomposetoolbarbuttontypemention]; [ Selfsetupbtn:@"Compose_trendbutton_background"highimage:@"compose_trendbutton_background_highlighted"Type:nycomposetoolbarbuttontypetrend]; [ Selfsetupbtn:@"Compose_emoticonbutton_background"highimage:@"compose_emoticonbutton_background_highlighted"Type:nycomposetoolbarbuttontypeemotion]; }return Self;}/** * Create a button * /- (void) Setupbtn: (NSString*) Image highimage: (NSString*) highimage Type: (Nycomposetoolbarbuttontype) type{UIButton*BTN = [[UIButtonALLOC] init]; [Btn setimage:[UIImageImagenamed:image] Forstate:uicontrolstatenormal]; [Btn setimage:[UIImageImagenamed:highimage] forstate:uicontrolstatehighlighted]; [BTN AddTarget: SelfAction@selector(Btnclick:) forcontrolevents:uicontroleventtouchupinside]; Btn. Tag= type; [ SelfADDSUBVIEW:BTN];} - (void) layoutsubviews{[SuperLayoutsubviews];//Set frame for all buttonsNsuinteger count = Self. Subviews. Count;CGFloatBTNW = Self. Width/count;CGFloatBTNH = Self. Height; for(Nsuinteger i =0; i<count; i++) {UIButton*BTN = Self. Subviews[i]; Btn. Y=0; Btn. Width= BTNW; Btn. x= i * BTNW; Btn. Height= BTNH; }}- (void) Btnclick: (UIButton*) btn{if([ Self. DelegateRespondstoselector:@selector(Composetoolbar:didclickbutton:)]) {//Nsuinteger index = (nsuinteger) (btn.x/btn.width);[ Self. DelegateComposetoolbar: SelfDidclickbutton:btn. Tag]; }}@end
Three: Call
Setting up proxies and implementing proxy methods
/** * Add toolbar * /-(void) setuptoolbar{Nycomposetoolbar *toolbar = [[Nycomposetoolbar alloc] init];Toolbar. Width= Self. View. Width;Toolbar. Height= -;Toolbar. Y= Self. View. Height-Toolbar. Height;Toolbar. Delegate= Self;[Self. ViewAddsubview:toolbar];Self. Toolbar= Toolbar;}
Proxy method
#pragma mark-nycomposetoolbardelegate- (void) Composetoolbar: (Nycomposetoolbar *) toolbar Didclickbutton: (nycomposetoolbarbuttontype) buttontype{Switch(ButtonType) { CaseNycomposetoolbarbuttontypecamera://Photo//[self opencamera];Nylog (@ "---take photos"); Break; CaseNycomposetoolbarbuttontypepicture://albumsNylog (@ "---album");//[self openalbum]; Break; CaseNycomposetoolbarbuttontypemention:// @Nylog (@"--- @"); Break; CaseNycomposetoolbarbuttontypetrend:// #Nylog (@"--- #"); Break; CaseNycomposetoolbarbuttontypeemotion://emoticons \ KeyboardNylog (@ "---expression"); Break; }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Cat Learning iOS Weibo project Combat (12) Send Weibo custom toolbar agent to implement click events