iOS Developer Library

Developer

UIKit Framework Reference UISimpleTextPrintFormatter Class Reference

Options
Deployment Target:

On This Page
Language:

UISimpleTextPrintFormatter

Instances of the UISimpleTextPrintFormatter class lay out plain text for printing, possibly over multiple pages. The class allows you to specify global font, color, and text alignment properties for the printed text.

To use this print formatter for a print job, create an instance of UISimpleTextPrintFormatter initialized with the text, set the text properties and the inherited layout properties, and add the object to the print job in one of two ways:

  • If a single print formatter is being used for the print job (with no additional drawing), assign it to the printFormatter property of the UIPrintInteractionController shared instance. The inherited startPage property identifies the beginning page of content with which the formatter is associated.

  • If you are using multiple formatters along with a page renderer, associate each print formatter with a starting page of the printed content. You often take this approach when you want to add content such as headers and footers to what the formatters provide. You have two ways of associating a print formatter with a UIPrintPageRenderer object:

    • You can add print formatters to the printFormatters property of the UIPrintPageRenderer object; the startPage property of the print formatter specifies the starting page.

    • You can add print formatters by calling addPrintFormatter:startingAtPageAtIndex: for each print formatter; the second parameter of this method specifies the starting page (and overrides any startPage value).

You can change the text at any time before drawing of the printable content begins. You cannot change the text after drawing begins.

Inheritance


Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 4.2 and later.
  • Returns a simple-text print formatter initialized with attributed text.

    Declaration

    Swift

    init(attributedText attributedText: NSAttributedString?)

    Objective-C

    - (instancetype)initWithAttributedText:(NSAttributedString *)attributedText

    Parameters

    attributedText

    A string of attributed text or nil if you intend to assign the text later.

    Return Value

    An initialized instance of UISimpleTextPrintFormatter or nil if the object could not be created.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

    See Also

    attributedText

  • Returns a simple-text print formatter initialized with plain text.

    Declaration

    Swift

    init(text text: String?)

    Objective-C

    - (instancetype)initWithText:(NSString *)text

    Parameters

    text

    A string of plain text or nil if you intend to assign the text later.

    Return Value

    An initialized instance of UISimpleTextPrintFormatter or nil if the object could not be created.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.2 and later.

    See Also

    text

  • A string of attributed text.

    Declaration

    Swift

    @NSCopying var attributedText: NSAttributedString!

    Objective-C

    @property(nonatomic, copy) NSAttributedString *attributedText

    Discussion

    You cannot change the value of this property once drawing begins for a print job. The delegate method printInteractionControllerWillStartJob: is called immediately before the formatting is set for the job.

    Assigning a value to this property also replaces the value in the text property with the same string data, albeit without any formatting information.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • text text Property

    A string of plain text.

    Declaration

    Swift

    var text: String!

    Objective-C

    @property(nonatomic, copy) NSString *text

    Discussion

    You cannot change the value of this property once drawing begins for a print job. The delegate method printInteractionControllerWillStartJob: is called immediately before the formatting is set for the job.

    Assigning a value to this property replaces the value in the attributedText property with the same string data, albeit without any inherent style attributes. Instead, the print formatter styles the new string using the text attribute properties of this class.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.2 and later.

  • font font Property

    The font of the printed text.

    Declaration

    Swift

    var font: UIFont!

    Objective-C

    @property(nonatomic, retain) UIFont *font

    Discussion

    If the value of this property is nil (the default), UIKit uses the standard system font, 12 points.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.2 and later.

  • color color Property

    The color of the printed text.

    Declaration

    Swift

    var color: UIColor?

    Objective-C

    @property(nonatomic, retain) UIColor *color

    Discussion

    If the value of this property is nil (the default), UIKit uses a black color when printing.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.2 and later.

  • The alignment of the printed text.

    Declaration

    Swift

    var textAlignment: NSTextAlignment

    Objective-C

    @property(nonatomic) NSTextAlignment textAlignment

    Discussion

    The default text alignment is UITextAlignmentLeft.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 4.2 and later.

    See Also

    font
    color