Created
December 27, 2019 09:26
-
-
Save alekseypotapov-dev/5c9283bc13b12fc1e7b368e99283a90e to your computer and use it in GitHub Desktop.
Changed drawTableHeaderTitles method of https://github.com/alekseypotapov-dev/PDFCreatorExample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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