Skip to content

Instantly share code, notes, and snippets.

@oliverbarreto
Created January 12, 2014 21:18
Show Gist options
  • Select an option

  • Save oliverbarreto/8390713 to your computer and use it in GitHub Desktop.

Select an option

Save oliverbarreto/8390713 to your computer and use it in GitHub Desktop.
Blur UIView Category (Credit: http://damir.me/ios7-blurring-techniques) Basically take a screenshot of a particular UIView and blur that image. But programmatically taking a screenshot in iOS 6, using renderInContext:, took too long. Fortunately iOS 7 includes a new method in UIView called drawViewHierarchyInRect:afterScreenUpdates: that does th…
// YourUIView.m (UIView)
#import "UIImage+ImageEffects.h"
-(UIImage *)blurredSnapshot
{
// Create the image context
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, self.window.screen.scale);
// There he is! The new API method
[self drawViewHierarchyInRect:self.frame afterScreenUpdates:NO];
// Get the snapshot
UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
// Now apply the blur effect using Apple's UIImageEffect category
UIImage *blurredSnapshotImage = [snapshotImage applyLightEffect];
// Or apply any other effects available in "UIImage+ImageEffects.h"
// UIImage *blurredSnapshotImage = [snapshotImage applyDarkEffect];
// UIImage *blurredSnapshotImage = [snapshotImage applyExtraLightEffect];
// Be nice and clean your mess up
UIGraphicsEndImageContext();
return blurredSnapshotImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment