Full screen inner shadow iOS
I'm wondering how I might be able to implement a full screen inner shadow effect, similar to when the UIAlertView pops开发者_开发百科 up. Is there an easy way to do this? Is there an api to bring up just the shadow portion of an alert in iOS? This is for iOS 4.0 and above by the way.
You could create a partially transparent image in Photoshop and add it as a subview. Something like this:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"inner-shadow.png"]];
[self.view addSubview:imageView];
Without having to increase the asset size of your app, you could create a simple UIView.
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView *fullscreenShadow = [[UIView alloc] initWithFrame:keyWindow.bounds];
fullscreenShadow.backgroundColor = [UIColor blackColor];
fullscreenShadow.alpha = 0.3;
[keyWindow addSubview:fullscreenShadow];
Adding it to the keyWindow will make it cover everything, except the UIStatusBar of course. I believe this will achieve your intended result. Combine it with a UIViewAnimation and bring the alpha up.
Below code will add shadow to our view use it in your way:
[self.yourView.layer setShadowColor:[UIColor blackColor].CGColor];
[self.yourView.layer setShadowOpacity:0.8];
[self.yourView.layer setShadowRadius:3.0];
[self.yourView.layer setShadowOffset:CGSizeMake(2.0, 2.0)];
精彩评论