You need to setup the graphics context first:
UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
More Related Contents:
- How to create a colored 1×1 UIImage on the iPhone dynamically?
- How to Rotate a UIImage 90 degrees?
- How to Convert UIView to PDF within iOS?
- Resize UIImage with aspect ratio?
- How to merge two UIImages?
- Loading/Downloading image from URL on Swift
- The simplest way to resize an UIImage?
- Getting a screenshot of a UIScrollView, including offscreen parts
- How can I mask a UIImageView?
- NSAttributedString background color and rounded corners
- How to compress of reduce the size of an image before uploading to Parse as PFFile? (Swift)
- UIImageView – How to get the file name of the image assigned?
- How do I make UILabel display outlined text?
- How do I take a full screen Screenshot in Swift?
- How to compress/resize image on iOS before uploading to a server?
- How would I tint an image programmatically on iOS?
- How to flip UIImage horizontally?
- Creating a UIImage from a UIColor to use as a background image for UIButton [duplicate]
- How to turn a CVPixelBuffer into a UIImage?
- UIImage imageNamed returns nil
- UICollectionView adding image to a cell
- iPhone – Draw transparent rectangle on UIView to reveal view beneath
- iOS UIImage clip to paths
- Get pixel data as array from UIImage/CGImage in swift
- How to set the opacity/alpha of a UIImage?
- UIBezierPath Triangle with rounded edges
- How can I get the height and width of an uiimage?
- Union UIBezierPaths rather than apend path
- Set custom images to the UIBarButtonItem but it doesn’t show any image
- Round top corners of a UIView and add border