Skip to content

Instantly share code, notes, and snippets.

@izzuddin91
Created December 20, 2018 09:03
Show Gist options
  • Save izzuddin91/a9a0bb5d65ab4464ac36367d8d96933c to your computer and use it in GitHub Desktop.
Save izzuddin91/a9a0bb5d65ab4464ac36367d8d96933c to your computer and use it in GitHub Desktop.
Swift iOS PDF
func getTextSize(text: String, font: UIFont!, textAttributes: [NSAttributedStringKey: Any]! = nil) -> CGSize {
let pageFrame = CGRect(x: 0.0, y: 0.0, width: 595.2, height: 841.8)
let testLabel = UILabel(frame: CGRect(x: 0.0, y: 0.0, width: pageFrame.size.width, height: 100))
if let attributes = textAttributes {
testLabel.attributedText = NSAttributedString(string: text, attributes: attributes)
}
else {
testLabel.text = text
testLabel.font = font!
}
testLabel.sizeToFit()
return testLabel.frame.size
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment