#import "FeedbackLabel.h"@implementationFeedbacklabel/*//Only override drawrect:if your perform custom drawing.//an empty implementation adversely affects performance Duri ng animation.-(void) DrawRect: (cgrect) Rect {//Drawing code}*/-(BOOL) canbecomefirstresponder{returnYES;}//features of "feedback" care-(BOOL) Canperformaction: (SEL) Action Withsender: (ID) sender{//return (Action = = @selector (copy:)); if(Action = = @selector (copy:) | | Action = = @selector (flag:) | | Action = = @selector (approve:) | | Action = =@selector (deny:)) {returnYES; } returnNO;}//implementation for copy-(void) Copy: (ID) sender{Uipasteboard*pboard =[Uipasteboard Generalpasteboard]; Pboard.string=Self.text;}//Uilabel The default is not to receive events, we need to add the touch event ourselves-(void) attachtaphandler{self.userinteractionenabled= YES;//General switch for user interactionUITapGestureRecognizer *touch =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Handtaplabel:)]; Touch.numberoftapsrequired=2; [Self addgesturerecognizer:touch]; //Long PressUilongpressgesturerecognizer *press =[[Uilongpressgesturerecognizer alloc]initwithtarget:self Action: @selector (longpress:)]; Press.minimumpressduration=1.0; [Self addgesturerecognizer:press]; }//Binding Events- (ID) initWithFrame: (cgrect) frame{ Self=[Super Initwithframe:frame]; if(self) {[self attachtaphandler]; } returnSelf ;}-(void) Handtaplabel: (uigesturerecognizer*) recognizer{[self becomefirstresponder]; Uimenucontroller*menu =[Uimenucontroller Sharedmenucontroller]; [Menu SetTargetRect:self.frame InView:self.superview]; [Menu Setmenuvisible:yes animated:yes];}- (void) Longpress: (Uilongpressgesturerecognizer *) Recognizer {if(Recognizer.state = =Uigesturerecognizerstatebegan) { //Tstableviewcell *cell = (Tstableviewcell *) Recognizer.view;[self becomefirstresponder]; UIMenuItem*flag = [[UIMenuItem alloc] Initwithtitle:@"Flag"Action: @selector (flag:)]; UIMenuItem*approve = [[UIMenuItem alloc] Initwithtitle:@"Approve"Action: @selector (approve:)]; UIMenuItem*deny = [[UIMenuItem alloc] Initwithtitle:@"Deny"Action: @selector (deny:)]; Uimenucontroller*menu =[Uimenucontroller Sharedmenucontroller]; [Menu Setmenuitems:[nsarray Arraywithobjects:flag, approve, deny, Nil]]; [Menu SetTargetRect:self.frame InView:self.superview]; [Menu Setmenuvisible:yes Animated:yes]; } }- (void) Flag: (ID) Sender {NSLog (@"Cell was flagged");}- (void) Approve: (ID) Sender {NSLog (@"Cell was approved");}- (void) Deny: (ID) Sender {NSLog (@"Cell was denied");}
Add long press Copy and custom popup menu to common controls