Some test text!

Search
Hamburger Icon

iOS / Guides

Customize the Document Viewer UI

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

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

Hide the Toolbar Switcher

documentController.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:

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

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

documentController.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:

NSMutableArray<PTToolItemGroup*>* mutableGroups = [documentController.toolGroupManager.groups mutableCopy];
    
[mutableGroups removeObjectsInArray:@[documentController.toolGroupManager.drawItemGroup, documentController.toolGroupManager.pensItemGroup]];
    
documentController.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.

PTToolItemGroup* annotateGroup = documentController.toolGroupManager.annotateItemGroup;

// tool buttons that exist currently
NSArray<UIBarButtonItem*>* defaultAnnotateGroupTools = annotateGroup.barButtonItems;

// new set of tools to replace current ones
NSMutableArray<UIBarButtonItem*>* newAnnotateGroupTools = [[NSMutableArray alloc] init];

// add all currently existing tools except for the ones we don't want
for(UIBarButtonItem* defaultToolItem in defaultAnnotateGroupTools)
{
    if( [defaultToolItem isKindOfClass:[PTToolBarButtonItem class]] )
    {
        PTToolBarButtonItem* toolBarButton = (PTToolBarButtonItem*)defaultToolItem;
        
        if( toolBarButton.toolClass == [PTTextHighlightCreate class] ||
             toolBarButton.toolClass == [PTTextUnderlineCreate class] )
        {
            // do not add this tool
            continue;
        }
        else
        {
            [newAnnotateGroupTools addObject:defaultToolItem];
        }
    }
    else
    {
        [newAnnotateGroupTools addObject:defaultToolItem];
    }
}

// assign tools to new array
documentController.toolGroupManager.annotateItemGroup.barButtonItems = [newAnnotateGroupTools copy];

Add a tool button to a toolbar

// create a mutable array of the current items in the annotation toolbar group
NSMutableArray<UIBarButtonItem*>* availableTools = [documentController.toolGroupManager.annotateItemGroup.barButtonItems mutableCopy];

// create a new toolbar item for freehand annotations
UIBarButtonItem* freeHandItem = [documentController.toolGroupManager createItemForToolClass:[PTFreeHandCreate class]];

// add the freehand annotation item to the front of the list
[availableTools insertObject:freeHandItem atIndex:0];

// assign the array back to the annotation toolbar group.
documentController.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.

// the image that will be used in the toolbar switcher menu
UIImage* image = [UIImage systemImageNamed:@"square.and.pencil"];

// the tools it will contain
UIBarButtonItem* freeHandItem = [documentController.toolGroupManager createItemForToolClass:[PTFreeHandCreate class]];
UIBarButtonItem* cloudyItem = [documentController.toolGroupManager createItemForToolClass:[PTCloudCreate class]];
UIBarButtonItem* stampItem = [documentController.toolGroupManager createItemForToolClass:[PTImageStampCreate class]];

// the name of the custom group, its image, and its tool items
PTToolItemGroup* customGroup = [PTToolItemGroup groupWithTitle:@"MyApps Group" image:image barButtonItems:@[freeHandItem, cloudyItem, stampItem]];

// add the tool group
documentController.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.

PTSelectableBarButtonItem* selectableItem = [[PTSelectableBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(customToolAction:)];
selectableItem.title = @"Custom Tool";

documentController.toolGroupManager.annotateItemGroup.barButtonItems = [documentController.toolGroupManager.annotateItemGroup.barButtonItems arrayByAddingObject:selectableItem];

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

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

Modify UINavigationBar Items

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

UIBarButtonItem* myItem = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"square.and.pencil"] style:UIBarButtonItemStylePlain target:nil action:nil];

documentController.navigationItem.rightBarButtonItems = [documentController.navigationItem.rightBarButtonItems arrayByAddingObject:myItem];

Tools can also be added:

UIBarButtonItem* freeHand = [documentController.toolGroupManager createItemForToolClass:[PTFreeHandCreate class]];

documentController.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.

// new button
UIBarButtonItem* myItem = [[UIBarButtonItem alloc] initWithImage:[UIImage systemImageNamed:@"square.and.pencil"] style:UIBarButtonItemStylePlain target:nil action:nil];
   
// spacer to keep evenly spaced buttons
UIBarButtonItem* spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

// new array
NSMutableArray* toolbarItems = [documentController.toolbarItems mutableCopy];

// add the new items
[toolbarItems addObjectsFromArray:@[spacer, myItem]];

// set the toolbarItems to the new items
documentController.toolbarItems = [toolbarItems copy];

Get the answers you need: Chat with us