UITextView自定义文字选择后的菜单

- (void)viewDidLoad {
	[super viewDidLoad];
	UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"分享到新浪微博" action:@selector(shareSina)];
	UIMenuController *menu = [UIMenuController sharedMenuController];
	[menu setMenuItems:[NSArray arrayWithObject:menuItem]];	
	[menuItem release];
}

- (void) shareSina {
	NSLog(@"%@", [textview.text substringWithRange:textview.selectedRange]);
}

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {   
	if(action == @selector(shareSina)) {        
		if(textview.selectedRange.length > 0)
			return YES;   
	}   
	return NO;
}

 UITextView自定义文字选择后的菜单

你可能感兴趣的:(ios,自定义,iPhone,菜单,UITextView)