IOS learning and ios learning routes
Menu events include cut, copy, select all, and share... this demo only supports copy and share
1. Define field inheritance and UITextField
-(BOOL) canPerformAction :( SEL) action withSender :( id) sender {if (action = @ selector (copy :)) {return YES;} return NO;}-(void) copy :( id) sender {[self resignFirstResponder]; // persistence, the content of the copy exit program is still in [[UIPasteboard generalPasteboard] setPersistent: YES]; // The copied content [[UIPasteboard generalPasteboard] setValue: self. text forPasteboardType: [UIPasteboardTypeListString objectAtIndex: 0];}
2. ViewController Loading
Field = [[CCField alloc] initWithFrame: CGRectMake (100,200,100, 40)]; field. backgroundColor = [UIColor greenColor]; [self. view addSubview: field]; UIMenuItem * specify Item = [[UIMenuItem alloc] initWithTitle: @ "share" action: @ selector (click)]; UIMenuController * menu = [UIMenuController sharedMenuController]; [menu setMenuItems: [NSArray arrayWithObjects: Outline item, nil];
3. The implementation of sharing, for example, the preparation work is here
SendMessageToWXReq * sendReq = [[SendMessageToWXReq alloc] init]; // use the text message sendReq. bText = YES; // sent to a list. The default value is 0 sendReq. scene = 0; sendReq. text = field. text; // send the shared information [WXApi sendReq: sendReq]; NSLog (@ "213 ");
Complete the demo in githud. Click here to view