Some test text!
Xamarin / Guides
You can edit the style properties of annoations.
The PTAnnotStyleViewController
class shows annotation style properties in a half-modal bottom sheet, or optionally in a popover view on large-screened devices such as iPads or large iPhones in landscape mode.
With this style editor, users can edit annotation styles easily with style presets as well as choosing their own colors through the color picker.
Half-Modal Bottom Sheet | Popover |
---|---|
The annotation style editor is part of the Tools library, so make sure you have added the Tools library to your project .
The annotation style state for the given annotation is managed by an PTAnnotStyle
instance. To create and display a new annotation style view controller from another view controller, first create and supply an PTAnnotStyle
instance to the PTAnnotStyleViewController
initializer:
// Initialize annot style with a Annot instance or PTAnnotType.
var annotStyle = new PTAnnotStyle(PTAnnotType.e_ptSquare);
var stylePicker = new PTAnnotStyleViewController(annotStyle);
// Save a strong reference to a half-modal presentation manager.
this.halfModalPresentationManager = new PTHalfModalPresentationManager();
// To show
this.PresentModalViewController(stylePicker, true);
PTAnnotStyle
can also be initialized with an PTAnnotType
, in which case the PTAnnotStyle
will operate on the default style properties for that annotation type. (The default style properties are the ones that are used when a new annotation of that type is created.)
To hide the annotation style view controller programmatically, call dismissViewControllerAnimated:completion
on either the presenting view controller or the annotation view controller itself.
To present the annotation style view controller in a popover, you should provide its presentation manager either:
sourceRect
ANDsourceView
OR
This will define the anchor point of the popover view. See the code sample above for an example of how to do this using an annotation's rect as the sourceRect
, and the PDFViewCtrl
as the sourceView
.
The annotation view controller does not commit the annotation style changes back to the annotation unless explicitly told to do so. To commit the annotation style changes, implement the annotStyleViewController:didCommitStyle:
and/or annotStyleViewController:didChangeStyle:
methods of the AnnotStyleViewControllerDelegate
protocol:
stylePicker.DidChangeStyle += (sender, e) =>
{
};
stylePicker.DidCommitStyle += (sender, e) =>
{
};
The annotStyleViewController:didCommitStyle:
method is called when the annotation style view controller is dismissed either by the user pressing the 'Done' button or de-selecting the current annotation. The optional annotStyleViewController:didChangeStyle:
method is called immediately after any annotation style property is changed by the user. For slider-controlled properties (thickness, opacity, etc.), an event notifying of the change is triggered when the user releases the slider control.
The saveAnnotStyleChanges:
helper method used above can be defined as follows:
void SaveAnnotStyleChanges(PTAnnotStyle annotStyle) {
var annot = TypeConvertHelper.ConvAnnotToManaged(annotStyle.Annot);
// Ensure annotation being edited is still valid.
if (currentAnnotation != annot || !annot.IsValid())
{
return;
}
try
{
pdfViewCtrl.DocLock(true);
annotStyle.SaveChanges();
currentAnnotation.RefreshAppearance();
pdfViewCtrl.UpdateWithAnnot(currentAnnotation, annotationPageNumber);
annotStyle.SetCurrentValuesAsDefaults();
}
catch (Exception ex)
{
}
finally
{
pdfViewCtrl.DocUnlock();
}
}
The call to setCurrentValuesAsDefaults
in the code above is not necessary if the saveValuesAsDefaults
property (enabled by default) is set, as in this case saveChanges
will automatically save the style as the new default style.
The sequence of document locking and annotation updates shown here is used throughout the Tools framework. For more information on document locking please see the dedicated guide .
Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales