Last active
January 10, 2025 06:23
-
-
Save wayne90040/fcde056c7ef86dcf1d148c8255dd80db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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