Skip to content

Instantly share code, notes, and snippets.

@alekseypotapov-dev
Created December 27, 2019 09:26
Show Gist options
  • Save alekseypotapov-dev/5c9283bc13b12fc1e7b368e99283a90e to your computer and use it in GitHub Desktop.
Save alekseypotapov-dev/5c9283bc13b12fc1e7b368e99283a90e to your computer and use it in GitHub Desktop.
Changed drawTableHeaderTitles method of https://github.com/alekseypotapov-dev/PDFCreatorExample
func drawTableHeaderTitles(titles: [String], drawContext: CGContext, pageRect: CGRect) {
// prepare title attributes
let textFont = UIFont.systemFont(ofSize: 16.0, weight: .medium)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .left
paragraphStyle.lineBreakMode = .byWordWrapping
let titleAttributes = [
NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font: textFont
]
// draw titles
let tabWidth = (pageRect.width - defaultOffset * 2) / CGFloat(3)
for titleIndex in 0..<titles.count {
let attributedTitle = NSAttributedString(string: titles[titleIndex].capitalized, attributes: titleAttributes)
let tabX = CGFloat(titleIndex) * tabWidth
let textRect = CGPoint(x: tabX + defaultOffset, y: defaultOffset)
attributedTitle.draw(at: textRect)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment