Skip to content

Instantly share code, notes, and snippets.

@josephchang10
Created January 12, 2017 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephchang10/821a246f5afbdee5e4f96732066d385a to your computer and use it in GitHub Desktop.
Save josephchang10/821a246f5afbdee5e4f96732066d385a to your computer and use it in GitHub Desktop.
根据文字计算高度
let fontSize: CGFloat = 22.0
func sizeHeightWithText(labelText: NSString,
fontSize: CGFloat,
textAttributes: [String : Any]) -> CGRect {
return labelText.boundingRect(
with: CGSize(width:fontSize, height:480),
options: NSStringDrawingOptions.usesLineFragmentOrigin,
attributes: textAttributes, context: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment