Customize the Document Viewer UI

The following snippets assume you are using a PTDocumentController called documentController:

1PTDocumentController *documentController = [[PTDocumentController alloc] init];

Hide the Toolbar Switcher

1documentController.toolGroupIndicatorView.hidden = YES;

Hide (and show) the annotation toolbar

The toolbar can be programmatically hidden by setting the mode to view group, which is a special group and the only group where the toolbar is hidden:

1documentController.toolGroupManager.selectedGroup = documentController.toolGroupManager.viewItemGroup;

The toolbar can be shown again by changing the group to any group other than view:

1documentController.toolGroupManager.selectedGroup = documentController.toolGroupManager.drawItemGroup;

Remove toolbars from the switcher

Toolbars can be removed by removing them from the toolGroupManager's groups array. The following code removes the "Draw" and "Pens" toolbars:

1NSMutableArray<PTToolItemGroup*>* mutableGroups = [documentController.toolGroupManager.groups mutableCopy];
2
3[mutableGroups removeObjectsInArray:@[documentController.toolGroupManager.drawItemGroup, documentController.toolGroupManager.pensItemGroup]];
4
5documentController.toolGroupManager.groups = [mutableGroups copy];

Remove buttons from a toolbar

The example below shows how to remove the text highlight and text underline button from a toolbar.

Disabling a tool type entirely

If you want to disable a tool entirely, from all toolbars and the long press menu, please use the annotations permissions system.

1PTToolItemGroup* annotateGroup = documentController.toolGroupManager.annotateItemGroup;
2
3// tool buttons that exist currently
4NSArray<UIBarButtonItem*>* defaultAnnotateGroupTools = annotateGroup.barButtonItems;
5
6// new set of tools to replace current ones
7NSMutableArray<UIBarButtonItem*>* newAnnotateGroupTools = [[NSMutableArray alloc] init];
8
9// add all currently existing tools except for the ones we don't want
10for(UIBarButtonItem* defaultToolItem in defaultAnnotateGroupTools)
11{
12 if( [defaultToolItem isKindOfClass:[PTToolBarButtonItem class]] )
13 {
14 PTToolBarButtonItem* toolBarButton = (PTToolBarButtonItem*)defaultToolItem;
15
16 if( toolBarButton.toolClass == [PTTextHighlightCreate class] ||
17 toolBarButton.toolClass == [PTTextUnderlineCreate class] )
18 {
19 // do not add this tool
20 continue;
21 }
22 else
23 {
24 [newAnnotateGroupTools addObject:defaultToolItem];
25 }
26 }
27 else
28 {
29 [newAnnotateGroupTools addObject:defaultToolItem];
30 }
31}
32
33// assign tools to new array
34documentController.toolGroupManager.annotateItemGroup.barButtonItems = [newAnnotateGroupTools copy];

Add a tool button to a toolbar

1// create a mutable array of the current items in the annotation toolbar group
2NSMutableArray<UIBarButtonItem*>* availableTools = [documentController.toolGroupManager.annotateItemGroup.barButtonItems mutableCopy];
3
4// create a new toolbar item for freehand annotations
5UIBarButtonItem* freeHandItem = [documentController.toolGroupManager createItemForToolClass:[PTFreeHandCreate class]];
6
7// add the freehand annotation item to the front of the list
8[availableTools insertObject:freeHandItem atIndex:0];
9
10// assign the array back to the annotation toolbar group.
11documentController.toolGroupManager.annotateItemGroup.barButtonItems = [availableTools copy];

Create a new toolbar

The code below creates a new toolbar that contains a free hand, cloudy and image stamp tool.

1// the image that will be used in the toolbar switcher menu
2UIImage* image = [UIImage systemImageNamed:@"square.and.pencil"];
3
4// the tools it will contain
5UIBarButtonItem* freeHandItem = [documentController.toolGroupManager createItemForToolClass:[PTFreeHandCreate class]];
6UIBarButtonItem* cloudyItem = [documentController.toolGroupManager createItemForToolClass:[PTCloudCreate class]];
7UIBarButtonItem* stampItem = [documentController.toolGroupManager createItemForToolClass:[PTImageStampCreate class]];
8
9// the name of the custom group, its image, and its tool items
10PTToolItemGroup* customGroup = [PTToolItemGroup groupWithTitle:@"MyApps Group" image:image barButtonItems:@[freeHandItem, cloudyItem, stampItem]];
11
12// add the tool group
13documentController.toolGroupManager.groups = [documentController.toolGroupManager.groups arrayByAddingObject:customGroup];

Add a button with fully custom behavior

Your app may need a button that does not invoke one of the built in annotation tools. The following code will add a button that calls a selector.

1PTSelectableBarButtonItem* selectableItem = [[PTSelectableBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(customToolAction:)];
2selectableItem.title = @"Custom Tool";
3
4documentController.toolGroupManager.annotateItemGroup.barButtonItems = [documentController.toolGroupManager.annotateItemGroup.barButtonItems arrayByAddingObject:selectableItem];

If you want to toggle the items selection, flip its selected property:

1-(void)customToolAction:(PTSelectableBarButtonItem*)button
2{
3 button.selected = !button.selected;
4}

Modify UINavigationBar Items

You can modify the navigation bar items. Here is an example of adding a new button (for the current size class):

1UIBarButtonItem* myItem = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"square.and.pencil"] style:UIBarButtonItemStylePlain target:nil action:nil];
2
3documentController.navigationItem.rightBarButtonItems = [documentController.navigationItem.rightBarButtonItems arrayByAddingObject:myItem];

Tools can also be added:

1UIBarButtonItem* freeHand = [documentController.toolGroupManager createItemForToolClass:[PTFreeHandCreate class]];
2
3documentController.navigationItem.rightBarButtonItems = [documentController.navigationItem.rightBarButtonItems arrayByAddingObject:freeHand];

Note that in the example above, de-selecting the tool button item needs to be implemented by the app, by listening to the Tool Did Change notification.

Add and Remove Toolbar Items (iPhone UI)

These are the buttons that appear at the bottom of the screen.

1// new button
2UIBarButtonItem* myItem = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"square.and.pencil"] style:UIBarButtonItemStylePlain target:nil action:nil];
3
4// spacer to keep evenly spaced buttons
5UIBarButtonItem* spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
6
7// new array
8NSMutableArray* toolbarItems = [documentController.toolbarItems mutableCopy];
9
10// add the new items
11[toolbarItems addObjectsFromArray:@[spacer, myItem]];
12
13// set the toolbarItems to the new items
14documentController.toolbarItems = [toolbarItems copy];

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales