Skip to content

Instantly share code, notes, and snippets.

@garethng
Created April 13, 2021 09:13
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 garethng/2a6e95a7d61cee0807e16e6f85e94cf8 to your computer and use it in GitHub Desktop.
Save garethng/2a6e95a7d61cee0807e16e6f85e94cf8 to your computer and use it in GitHub Desktop.
convert label to icon
public extension NSView {
var image: NSImage? {
guard let bitmapImageRep = bitmapImageRepForCachingDisplay(in: bounds) else { return nil }
cacheDisplay(in: bounds, to: bitmapImageRep)
guard let cgImage = bitmapImageRep.cgImage else { return nil }
return NSImage(cgImage: cgImage, size: bounds.size)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment