How to update toolbar button color

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?

Hi Saikat,

Thank you for your feedback. Can you please try the attached code to see if it works? PTAnnotEditTool and PTToolGroupToolbar are overridden.

Thank you,

ViewController.swift (3.3 KB)

After adding this view controller in the above project facing a crash on GroupToolbar class initialization

ViewController.swift (3.5 KB)

Can you please help me out with this?


Hi Saikat,

You could try adding this in GroupToolbar class:

override init(frame: CGRect) {
    super.init(frame: frame)

Please let us know how this works for you.

Thank you,

1 Like

Awesome, the Crash got resolved.
It is working for us.
Will play around more on this and let you know.

Thanks Yifan

Hi @Yifan_Zhang ,

With this solution, we are facing one issue. If we change the color of the annotation and at that time if another tool is selected its icon is also getting changed. Attaching a video for better understanding.

Steps to reproduce:

  • Draw any markup. eg. using a highlighter.
  • Select the Callout markup tool from toolbar.
  • Select drawn highlighter markup and change the color of that annotation.
  • Callout markup and highlighter both tool’s icon and color are getting change. It should change only the highlighter tool icon.

This is happening with all tools. Can you please help us with how we can fix that?


Controller file:
ViewController.swift (4.8 KB)

My apologies. Please try this:

    @objc func colorDidChange(notification: Notification) {
        let userInfo = notification.userInfo!
        let style = userInfo["style"] as! PTAnnotStyle
        let type = userInfo["type"] as! PTExtendedAnnotType
        let presets = PTAnnotationStyleManager.default.stylePresets(forAnnotationType: type)
        var styles = presets.styles
        styles[Int(presets.selectedIndex)] = style
        presets.styles = styles
        PTAnnotationStyleManager.default.setStylePresets(presets, forAnnotationType: type)
        for item in self.items ?? [] {
            if let toolItem = item as? PTToolBarButtonItem {
                if toolItem.toolClass?.annotType == type {

Thank you,


Hi @ @Yifan_Zhang , Thanks for the solution.

We have tried it and it is working fine except for these tools.

Can you tell us how we can implement the same for these also?

Thanks :slight_smile:

Hi Rankit,

These annotation types are managed by PTPolyLineEditTool, you could implement the method annotStyleViewController(_ : didChange: ) in PTPolyLineEditTool's subclass, the same way as in MyAnnotEditTool.

Please let us know if this helps.


1 Like

It worked. Thanks @Yifan_Zhang :slight_smile:

Hi @Yifan_Zhang ,

We are having one crash, Here I am attaching sample code and some screenshots.

Steps to reproduce:

  1. Add PDFNet and Tools xcframework in the framework folder.
  2. Run the project and click on PDFTron button which will navigate to DocController.
  3. Add any markup and change its color from the style option.
  4. Go back from the navigation bar button and again press PDFTron button
  5. App will crash

If we comment out this code in GroupToolbar class, it is working fine.

Crash :

Can you please tell us How can we fix it?

Code Attachment: (78.9 KB)

Hi Rankit,

Thank you for reporting the issue.

We are able to reproduce this and are investigating for the root cause.

To avoid the crash for now, please try the attached code. Free text types are not suitable for changing styles in tool manager’s callback. (100.3 KB)

Please let us know if you have any other questions.