Skip to content

Instantly share code, notes, and snippets.

@lamlv2305
Last active February 27, 2018 07:43
Show Gist options
  • Save lamlv2305/829cc810f8554bc02c4e28fa1109def2 to your computer and use it in GitHub Desktop.
Save lamlv2305/829cc810f8554bc02c4e28fa1109def2 to your computer and use it in GitHub Desktop.
func sizeOfString (string: String, constrainedToWidth width: Double) -> CGSize {
let attributes = [NSFontAttributeName:self,]
let attString = NSAttributedString(string: string,attributes: attributes)
let framesetter = CTFramesetterCreateWithAttributedString(attString)
return CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRange(location: 0,length: 0), nil, CGSize(width: width, height: DBL_MAX), nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment