Customize the Menu of Text Editing
When you enter the editing mode, the PDF document will also enter the corresponding interaction status based on different operations. In different interaction statuses, a context menu like UIMenuController
pops up, and the context menu calls back to different interfaces with different operation classes. Here are the different interaction statuses:
ComPDFKit provides default menu options for copying, cutting, deleting, pasting, etc.
- (NSArray<UIMenuItem *> *)menuItemsEditingAtPoint:(CGPoint)point forPage:(CPDFPage *)page {
NSArray * items = [super menuItemsEditingAtPoint:point forPage:page];
NSMutableArray *menuItems = [NSMutableArray array];
if (items)
[menuItems addObjectsFromArray:items];
self.menuPoint = point;
self.menuPage = page;
if(CEditingSelectStateEmpty == self.editStatus) {
UIMenuItem *addTextItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Add Text", nil)
action:@selector(addTextEditingItemAction:)] autorelease];
UIMenuItem *addImageItem = [[[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Add Image", nil)
action:@selector(addImageEditingItemAction:)] autorelease];
[menuItems addObject:addImageItem];
[menuItems addObject:addTextItem];
}
return menuItems;
}
When selecting a text block or a certain area, you can use editStatus:
of CPDFView
to get the current text-editing status. Here are the introductions to each status.
- CEditingSelectStateEmpty
does not enter the text-editing status.
- CEditingSelectStateEditTextArea
selects a text block without entering the text-editing status.
- CEditingSelectStateEditNoneText
enters the text-editing status without selecting text.
- CEditingSelectStateEditSelectText
enters the text-editing status and selects text.