Skip to content

Instantly share code, notes, and snippets.

@dsxsxsxs
Created January 15, 2019 03:14
Show Gist options
  • Save dsxsxsxs/daee1312f236ddc7fc6a6f3ced6fce27 to your computer and use it in GitHub Desktop.
Save dsxsxsxs/daee1312f236ddc7fc6a6f3ced6fce27 to your computer and use it in GitHub Desktop.
swift 4 size of string
extension String {
var size: CGSize {
return size()
}
public func size(usingFont font: UIFont?) -> CGSize {
let f = font ?? UIFont.systemFont(ofSize: 16)
let attributes = [NSAttributedStringKey.font: f]
return self.size(withAttributes: attributes)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment