This sample demonstrates how to subclass built-in Apryse components when integrating the Flutter Library: https://docs.apryse.com/documentation/ios/get-started/flutter/ios/
The implementation is the same as when using the native iOS SDK: https://docs.apryse.com/documentation/ios/guides/tools/customization/#override-classes
This sample demonstrates how to subclass the PTFormFillTool
and override its currentAnnotation
property to add an arrow image to the active form field.
Navigate to the ios directory in the app and open the .xcworkspace
file, this will launch Xcode.
- Use the
CMD-N
keyboard shortcut or go toFile > New > File…
in the menu bar. - Select
Cocoa Touch Class
from the dialog and pressNext
- Enter your class name in the
Class
field and select which class you want to override in theSubclass of
field. In this sample we have added a new class calledMyFormFillTool
which is a subclass ofPTFormFillTool
. - If you chose to create your file in the Swift language then you should make sure to select
Yes
if it asks you to create the bridging header.
Open your newly-created file in Xcode and import the Tools library at the top of the file, e.g. below any other imports such as UIKit:
import UIKit
import Tools
Add the customizations you require to your subclass, e.g overriding internal properties.
In this sample we have overridden the currentAnnotation
property to add an arrow view when the property is set.
class MyFormFillTool : PTFormFillTool
{
var formArrowView: UIImageView?
override var currentAnnotation: PTAnnot?
{
get {
return super.currentAnnotation
}
set {
self.addArrowView(to: newValue)
super.currentAnnotation = newValue
}
}
func addArrowView(to annotation:PTAnnot?){
guard let pdfViewCtrl else {return}
if let formArrowView
{
pdfViewCtrl.removeFloating(formArrowView)
}
if let annotation,
let rect = annotation.getRect(),
let image = UIImage(systemName: "arrowtriangle.right.fill"),
let markerRect = PTPDFRect(x1: rect.x1 - 20, y1: rect.y1, x2: rect.x1, y2: rect.y2)
{
formArrowView = UIImageView(image: image)
if let formArrowView {
pdfViewCtrl.addFloating(formArrowView, toPage: Int32(self.annotationPageNumber), withPageRect: markerRect, noZoom: false)
}
}
}
}
To register the subclass with the SDK you will need to declare the override early in your app's lifecycle (before any Apryse components are loaded). A good place to do this is inside your AppDelegate.
- Open the
AppDelegate.swift
file in Xcode - Import the Tools library as well as your bridging header if you wrote your class in Swift:
import Tools
- Inside the
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
function you would call thePTOverrides
method to register your class:
PTOverrides.addOverriddenClass(MyFormFillTool.self)
You can now run your app and you should see the customizations you have added. Select a form field and an arrow should appear next to the field.