Created
December 20, 2018 09:03
-
-
Save izzuddin91/a9a0bb5d65ab4464ac36367d8d96933c to your computer and use it in GitHub Desktop.
Swift iOS PDF
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 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