How to update toolbar button color

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:



To hide presets on iPad, you could override PTToolGroupToolbar and in the subclass, add:

- (void)setPresetsViewHidden:(BOOL)hidden
    [super setPresetsViewHidden:YES];

- (void)setPresetsViewHidden:(BOOL)hidden animated:(BOOL)animated
    [super setPresetsViewHidden:YES animated:animated];

We are investigating an approach for you to update toolbar button colour and will let you know when we have an update.

Thank you,

Hi @Yifan_Zhang ,

Can you please share how can we do that?
documentController.toolGroupToolbar = GroupToolbar()
we are getting toolGroupToolbar is get only property error.

class GroupToolbar: PTToolGroupToolbar {
    override func  setPresetsViewHidden(_ hidden: Bool, animated: Bool) {
    super.setPresetsViewHidden(true, animated: animated)

We have create subclass like this to and now we are not able to assign it to toolGroupToolbar. Can you please share the example.


Here is an example to override a PDFTron class with a subclass (PTOverrides Class Reference):

PTOverrides.overrideClass(PTToolGroupToolbar.self, with: GroupToolbar.self)

This should be called before documentController is created.


1 Like

Hi @rankit.agarwal,

We recently released v9.2.2 of the PDFTron iOS SDK and we added an API to set the style (colours) of the icon of a PTToolBarButtonItem:

// Get the array of items in the default Draw toolbar
NSArray *drawItems = documentController.toolGroupToolbar.toolGroupManager.drawItemGroup.barButtonItems;

// Find the first ink tool item
PTToolBarButtonItem *inkItem = [drawItems objectAtIndex:[drawItems indexOfObjectPassingTest:^BOOL(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
    return ((PTToolBarButtonItem*)obj).toolClass == [PTFreeHandCreate class];
// Create a new PTAnnotStyle and set its stroke color
PTAnnotStyle *style = [[PTAnnotStyle alloc] initWithAnnotType:PTExtendedAnnotTypeInk];
[style setStrokeColor:UIColor.greenColor];

// Set the style of the item's image
[inkItem setImageStyle:style];

Please let us know if you are able to test it out.

Are there any other remaining issues for which you need guidance or assistance?

Hi @Jamie_Dassoulas,

You have provided a good solution for the PTFreeHandCreate tool code. We want to make it dynamic for any tool. and we are trying this with the following approach.

How can we get the tool name from annotation (PTAnnot)? [line no 152 in img]

(Our purpose: How to update toolbar button image color?
on changing annotation color. tool of that annotation should change to the same color.)


Hi @rankit.agarwal,

I think you could use the following (this code is Objective-C but you should be able to use the same APIs in swift):

- (void)toolManager:(PTToolManager *)toolManager annotationModified:(PTAnnot *)annotation onPageNumber:(unsigned long)pageNumber
    for (PTToolGroup *group in self.toolGroupManager.groups) {
        for (UIBarButtonItem *item in group.barButtonItems) {
            if ([item isKindOfClass:[PTToolBarButtonItem class]]) {
                PTToolBarButtonItem *toolItem = (PTToolBarButtonItem *)item;
                if ([toolItem.toolClass annotType] == [annotation extendedAnnotType]) {
                    PTAnnotStyle *style = [[PTAnnotStyle allocOverridden] initWithAnnot:annotation];
                    [toolItem setImageStyle:style];
1 Like

Yes it worked thanks @Jamie_Dassoulas

Hi @Jamie_Dassoulas
We have implemented as you suggested,

   func toolManager(_ toolManager: PTToolManager, annotationModified annotation: PTAnnot, onPageNumber pageNumber: UInt) {
    func setToolbarColorForAnnotation(_ annot: PTAnnot){
        let drawclass = documentController.toolGroupManager.annotateItemGroup.barButtonItems;
        let tool = drawclass?.first(where: { button in
            (button as! PTToolBarButtonItem).toolClass?.annotType == annot.extendedAnnotType

        let style = PTAnnotStyle(annotType: annot.extendedAnnotType)
        (tool as! PTToolBarButtonItem).setImageStyle(style)

But after adding callout annotation, the app is getting freeze when moving it.
If we comment out this function it is working fine, Can you please check and help is it correct implementation?

Hi @rankit.agarwal,

We have reproduced this and are working on a fix.

Hi @Jamie_Dassoulas ,

→ This toolbar color change is also causing issues in Text Annotations, Can you please check that also?

→ And also like android, is it possible for you to handle the code from the library side like this? [How to update toolbar button image color? - #7 by Shirley_Gong]


Hi @rankit.agarwal,

We have a fix for the callout and text issue available for testing in this build:



Are you able to try that and let us know if it works?

Hi @Jamie_Dassoulas ,

In this build, the toolbar color is changing but next time same new color is not been selected for annotation.

Attaching video for better understaning.

Hi @Jamie_Dassoulas ,
Any update on this? Kindly update

Hi @rankit.agarwal,

Unfortunately I haven’t been able to reproduce this, do you have some more customizations in your code?
Attached is a video showing my test as well as the ViewController.swift file I used.

ViewController.swift (2.3 KB)

Hi @Jamie_Dassoulas ,

We are using
(tool as! PTToolBarButtonItem).setImageStyle(style)

and in your vc it is
(tool as! PTToolBarButtonItem).setImageFor(style)

setImageFor is not available in latest experimental build version: 9.3079841
Can you share the link again which version to try?

Hi @rankit.agarwal,

Apologies, that was just a copy and paste error from referencing an older version of the API.
(tool as! PTToolBarButtonItem).setImageStyle(style) is the correct implementation.

I just tested again with this and am still unable to reproduce the issue.

Hi @Jamie_Dassoulas ,

We replace our code with your given view controller but still it is not working.

Just to confirm, we are downloading SDK from: PDFTron Systems Inc. | Nightly

Device - iPad Air 4th gen simulator
os version - 15.4

Version :

Can you please again share the SDK link which we can try for this and the whole project zip file?

Hi @rankit.agarwal,

Are you able to try using this nightly build:

CocoaPods Link

DMG Download

My ViewController.swift can just be used to replace the ViewController in the SwiftSample in the DMG download.

Hi @Jamie_Dassoulas

We are using Dynamic PDFnet XCFframework from above DMG mentioned URL: GitHub - saikat90/PDFSwiftSample

Steps to run the project:

Tools XCFramework are already there in the Github URL
PDFNet XCFramework we need to download from the above DMG mentioned URL

For highlighter Markup, it is not working for us

Let us know
What are we doing wrong?