Created
June 6, 2019 18:41
-
-
Save Tulakshana/f5e5f64af316c97de0d55478e6647e59 to your computer and use it in GitHub Desktop.
Generate an UIImage from a NSAttributedString
This file contains 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
import UIKit | |
extension NSAttributedString { | |
func image(size: CGSize) -> UIImage? { | |
UIGraphicsBeginImageContext(size) | |
self.draw(at: CGPoint.zero) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment