Skip to content

Instantly share code, notes, and snippets.

@wayne90040
Last active January 10, 2025 06:23
Show Gist options
  • Save wayne90040/fcde056c7ef86dcf1d148c8255dd80db to your computer and use it in GitHub Desktop.
Save wayne90040/fcde056c7ef86dcf1d148c8255dd80db to your computer and use it in GitHub Desktop.
extension String {
func image() -> UIImage? {
let size = CGSize(width: 20, height: 22)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
UIColor.clear.set()
let rect = CGRect(origin: .zero, size: size)
UIRectFill(CGRect(origin: .zero, size: size))
(self as AnyObject).draw(in: rect, withAttributes: [.font: UIFont.systemFont(ofSize: 15)])
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment