PSPDFTextSelectionView

Objective-C


@interface PSPDFTextSelectionView
    : UIView <AVSpeechSynthesizerDelegate, PSPDFOverridable>

Swift

class TextSelectionView : UIView, AVSpeechSynthesizerDelegate, Overridable

Handles text and image selection on a page.

Note

Requires the Features.textSelection feature flag.

Don’t manually create this class. The initializer here is not exposed.

The selection color is determined by the tintColor property inherited from UIView. On Mac Catalyst, the tintColor is set to [NSColor selectedContentBackgroundColor] & unemphasizedSelectedContentBackgroundColor, depending if the current window is the key window or not.

  • The text selection delegate.

    Declaration

    Objective-C

    @property (nonatomic, weak) id<PSPDFTextSelectionViewDelegate> _Nullable delegate;

    Swift

    weak var delegate: TextSelectionViewDelegate? { get set }
  • Currently selected glyphs.

    Note

    Use sortedGlyphs: to pre-sort your glyphs if you manually set this.

    Warning

    This method expects glyphs to be sorted in reading order.

    Declaration

    Objective-C

    @property (nonatomic, copy, null_resettable) NSArray<PSPDFGlyph *> *selectedGlyphs;

    Swift

    var selectedGlyphs: [PSPDFGlyph]! { get set }
  • Currently selected text. Set via setting selectedGlyphs. Use discardSelection to clear.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly, nullable) NSString *selectedText;

    Swift

    var selectedText: String? { get }
  • Currently selected image.

    Declaration

    Objective-C

    @property (nonatomic, nullable) PSPDFImageInfo *selectedImage;

    Swift

    var selectedImage: PSPDFImageInfo? { get set }
  • The selection alpha value. Defaults to 0.2.

    Declaration

    Objective-C

    @property (nonatomic) CGFloat selectionAlpha;

    Swift

    var selectionAlpha: CGFloat { get set }
  • Currently selected text, optimized for searching

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly, nullable) NSString *trimmedSelectedText;

    Swift

    var trimmedSelectedText: String? { get }
  • To make it easier to select text, we slightly increase the frame margins. Defaults to 4 pixels.

    Declaration

    Objective-C

    @property (nonatomic) CGFloat selectionHitTestExtension;

    Swift

    var selectionHitTestExtension: CGFloat { get set }
  • An NSArray of boxed CGRects for every selected block, in view coordinates.

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSArray<NSValue *> *_Nonnull selectionRects;

    Swift

    var selectionRects: [NSValue] { get }
  • The rect (in view coordinates) for the first block that is currently selected, or CGRectZero if nothing is selected. Note that this will return the rect for a selected image too. Using this property is much quicker than doing selectionRects.firstObject.CGRectValue.

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGRect rectForFirstBlock;

    Swift

    var rectForFirstBlock: CGRect { get }
  • The rect (in view coordinates) for the last block that is currently selected, or CGRectZero if nothing is selected. Note that this will return the rect for a selected image too. Using this property is much quicker than doing selectionRects.lastObject.CGRectValue.

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGRect rectForLastBlock;

    Swift

    var rectForLastBlock: CGRect { get }
  • Updates the UIMenuController if there is a selection. Returns YES if a menu is displayed.

    Declaration

    Objective-C

    - (BOOL)updateMenuAnimated:(BOOL)animated;

    Swift

    func updateMenu(animated: Bool) -> Bool
  • Update the selection (text menu).

    Note

    animated is currently ignored.

    Declaration

    Objective-C

    - (void)updateSelectionAnimated:(BOOL)animated;

    Swift

    func updateSelection(animated: Bool)
  • Clears the current selection.

    Declaration

    Objective-C

    - (void)discardSelectionAnimated:(BOOL)animated;

    Swift

    func discardSelection(animated: Bool)
  • Required if glyph frames change.

    Declaration

    Objective-C

    - (void)clearCache;

    Swift

    func clearCache()
  • Currently has a text/image selection?

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL hasSelection;

    Swift

    var hasSelection: Bool { get }
  • This method sorts the passed in glyphs by reading order.

    Declaration

    Objective-C

    - (nonnull NSArray<PSPDFGlyph *> *)sortedGlyphs:
        (nonnull NSArray<PSPDFGlyph *> *)glyphs;

    Swift

    func sortedGlyphs(_ glyphs: [PSPDFGlyph]) -> [PSPDFGlyph]

    Parameters

    glyphs

    The glyphs that are to be sorted.

    Return Value

    A new array of the passed in glyphs sorted according to their reading order.

  • Debugging feature, visualizes the text blocks.

    Declaration

    Objective-C

    - (void)showTextFlowData:(BOOL)show animated:(BOOL)animated;

    Swift

    func showTextFlowData(_ show: Bool, animated: Bool)