hgiraud
hgiraud

Reputation: 25

Long text on multiple pages

I need your help: I have a long text to draw. When it reaches the bottom of the page, how can I do for this text to automatically continue on a new page ?

    func addBodyText(pageRect: CGRect, myText: String, textFormat: UIFont.Weight, textSize: CGFloat, OrigXcm: CGFloat, OrigYcm: CGFloat, textColor: UIColor) {

    let myTextFont = UIFont.systemFont(ofSize: textSize, weight: textFormat)
    
    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.alignment = .justified
    paragraphStyle.lineBreakMode = .byWordWrapping
    
    let textAttributes: [NSAttributedString.Key: Any] =
    [NSAttributedString.Key.paragraphStyle: paragraphStyle, NSAttributedString.Key.font: myTextFont, NSAttributedString.Key.foregroundColor: textColor]
    let attributedText = NSAttributedString(string: myText, attributes: textAttributes)
    let textStringSize = attributedText.size()
    
    OrigXin = OrigXcm * 72 / 2.54
    let OrigYin = OrigYcm * 72 / 2.54
    
    let textStringRect = CGRect(x: OrigXin,
             y: OrigYin, width: pageRect.width - 60,
                                height: pageRect.height - OrigYin - 20)
    attributedText.draw(in: textStringRect)
}

` I thank you in advance !

Upvotes: 0

Views: 9

Answers (0)

Related Questions