Skip to content

Instantly share code, notes, and snippets.

@Tulakshana
Created June 6, 2019 18:41
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 Tulakshana/f5e5f64af316c97de0d55478e6647e59 to your computer and use it in GitHub Desktop.
Save Tulakshana/f5e5f64af316c97de0d55478e6647e59 to your computer and use it in GitHub Desktop.
Generate an UIImage from a NSAttributedString
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