How to make vignette effect on iOS?

When the UIAlertViews message appears, a vignette effect is applied in the background. That is, the edges are darker and the center is lighter.

vignette iOS

I was wondering if this vignette effect was built into Cocoa Touch. I would like to show a vignette for one of my custom views.

+5
source share
5 answers

It is built into UIKit (since UIAlertView is part of UIKit), but it is not publicly available.

However, it should not be too difficult to create the same effect. This is just a radial gradient that you can use in code or in Photoshop.

: , - _UIAlertNormalizingOverlayWindow :

_UIAlertNormalizingOverlayWindow
_UIAlertOverlayWindow
UIWindow
+2

- uialertview . , . ,

+2

VignetteEffect UIView

-drawRect::

- (void)drawRect:(CGRect)rect
{

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGColorSpaceRef colSp = CGColorSpaceCreateDeviceRGB();

    CGGradientRef gradient = CGGradientCreateWithColors(colSp, (__bridge CFArrayRef)[NSArray arrayWithObjects:(id)[[UIColor colorWithRed:0 green:0 blue:0 alpha:0] CGColor], (id)[[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5] CGColor], nil], 0);

    CGContextDrawRadialGradient(context, gradient, self.center, 0, self.center, self.frame.size.height+self.frame.size.height/4, 0);

    CGColorSpaceRelease(colSp);
    CGGradientRelease(gradient);

}

.

, . . .

+2

SVProgressHud , , SVProgressHUDMaskTypeGradient.

+1

I dispute the selected answer is incorrect and potentially dangerous. Here is my solution:

I copied the gradient drawing code from SVProgressHud into my fork from SSGradientView:

SSGradientView *vignette = [SSGradientView new];
vignette.frame = [UIScreen mainScreen].currentBounds;
vignette.backgroundColor = [UIColor clearColor];
vignette.direction = SSGradientViewDirectionRadial;
UIColor *startColor = // We just need the colorspace.
UIColor *endColor = // Visible vignette color.
vignette.colors = @[
[startColor colorWithAlphaComponent:0.0f], 
[endColor colorWithAlphaComponent:1.0f] ];
vignette.locations = @[ @0.4f, @1.0f ];
[view insertSubview:vignette atIndex:0]; // Or equivalent.
+1
source

All Articles