Add long press Copy and custom popup menu to common controls

Source: Internet
Author: User

#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

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.