PSPDFTextSelectionView

Objective-C


@interface PSPDFTextSelectionView
    : UIView <AVSpeechSynthesizerDelegate, PSPDFOverridable>

Swift

class TextSelectionView : UIView, AVSpeechSynthesizerDelegate, Overridable

The view that handles text and image selection on a page view.

The color of the selection blocks and handles is determined by tintColor. In apps built with Mac Catalyst, the tint color is set to .selectedContentBackground or .unemphasizedSelectedContentBackground, depending on whether the text selection view’s window is key or not.

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

  • The text selection view’s delegate.

    Declaration

    Objective-C

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

    Swift

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

    Setting this property is equivalent to calling the PSPDFPageView/selectGlyphs:presentMenu:animated: method with pre-sorted glyphs, and with false for both presentMenu and animated parameters. Setting nil value is equivalent to setting an empty array.

    Note

    Selecting glyphs requires the Text Selection feature to be enabled for your license. Otherwise, setting this property will have no effect.

    Important: Setting this property will deselect any currently selected glyphs or image in this text selection view.

    Warning: This property expects glyphs to be pre-sorted in reading order. Use sortedGlyphs: before setting this property directly, or use the PSPDFPageView/selectGlyphs:presentMenu:animated: method which will perform the sorting automatically.

    Declaration

    Objective-C

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

    Swift

    var selectedGlyphs: [PSPDFGlyph]! { get set }
  • The currently selected text, derived from selectedGlyphs.

    Declaration

    Objective-C

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

    Swift

    var selectedText: String? { get }
  • The currently selected text, but optimized for searching.

    Declaration

    Objective-C

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

    Swift

    var trimmedSelectedText: String? { get }
  • Sort the given glyphs in the reading order.

    Declaration

    Objective-C

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

    Swift

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

    Return Value

    A new array of the glyphs sorted in the reading order.

  • Invalidate the internal cache of glyph geometries. This method must be called if glyph frames are expected to have changed.

    Declaration

    Objective-C

    - (void)clearCache;

    Swift

    func clearCache()
  • The currently selected image.

    Setting this property is equivalent to calling the PSPDFPageView/selectImage:presentMenu:animated: method with false for both presentMenu and animated parameters.

    Note

    Selecting images requires the Text Selection feature to be enabled for your license. Otherwise, setting this property will have no effect.

    Important: Setting this property will deselect any currently selected glyphs or image in this text selection view.

    Declaration

    Objective-C

    @property (nonatomic, nullable) PSPDFImageInfo *selectedImage;

    Swift

    var selectedImage: PSPDFImageInfo? { get set }
  • The boolean value that indicates whether there are any selected glyphs or selected image in this view.

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL hasSelection;

    Swift

    var hasSelection: Bool { get }
  • The array of CGRect values for every selection block. For example, if three lines of text are selected, this array will contain three rects. These rects are in the coordinate space of self.

    Declaration

    Objective-C

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

    Swift

    var selectionRects: [NSValue] { get }
  • The first rect in the selectionRects array or .zero if no glyphs or image is currently selected. Using this property is much quicker than doing selectionRects.first?.cgRectValue. This rect is in the coordinate space of self.

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGRect rectForFirstBlock;

    Swift

    var rectForFirstBlock: CGRect { get }
  • The last rect in the selectionRects array or .zero if no glyphs or image is currently selected. Using this property is much quicker than doing selectionRects.last?.cgRectValue. This rect is in the coordinate space of self.

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGRect rectForLastBlock;

    Swift

    var rectForLastBlock: CGRect { get }
  • Lay out the selection blocks again. This method must be called if the bounds of the text selection view are expected to have changed.

    Declaration

    Objective-C

    - (void)updateSelectionAnimated:(BOOL)animated;

    Swift

    func updateSelection(animated: Bool)
  • The alpha value of the selection rect views. Default: 0.2.

    Declaration

    Objective-C

    @property (nonatomic) CGFloat selectionAlpha;

    Swift

    var selectionAlpha: CGFloat { get set }
  • Extra padding taken into consideration when determining the selectable frames of glyphs. This makes it easier to select small text. Default: 4.

    Declaration

    Objective-C

    @property (nonatomic) CGFloat selectionHitTestExtension;

    Swift

    var selectionHitTestExtension: CGFloat { get set }
  • Visualize the frames of glyphs for debugging purposes.

    Declaration

    Objective-C

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

    Swift

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

    Deprecated in PSPDFKit 12.3 for iOS. Use ‘PDFPageView.discardSelection(animated:)’ instead.

    Deselect the currently selected text or image.

    Warning

    This method is deprecated. To discard the current selection on a given page view, use the PSPDFPageView/discardSelectionAnimated: method instead.

    Declaration

    Objective-C

    - (void)discardSelectionAnimated:(BOOL)animated;

    Swift

    func discardSelection(animated: Bool)
  • Deprecated

    Deprecated in PSPDFKit 12.3 for iOS. Use ‘PDFPageView.select(glyphs:presentMenu:animated:)’ or ‘PDFPageView.select(image:presentMenu:animated:)’ instead.

    Display the menu for currently selected text or image, if any.

    Warning

    This method is deprecated. To display a menu for selected glyphs, use the PSPDFPageView/selectGlyphs:presentMenu:animated: method with true for presentMenu parameter. To display a menu for selected image, use the PSPDFPageView/selectImage:presentMenu:animated: method.

    Declaration

    Objective-C

    - (BOOL)updateMenuAnimated:(BOOL)animated;

    Swift

    func updateMenu(animated: Bool) -> Bool

    Return Value

    A boolean value that indicates whether a menu was displayed as a result of calling this method.