Full screen inner shadow iOS - 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)];

Related

How to set Shadow for a UISegmentedControl?

I have this method applyShadow which applies the shadow , and this works fine for UIViews and for UINavigationBar,but When I try it to UISegmentedControl, it doesnt work.
-(void) applyShadow
{
[self.layer setShadowOffset:CGSizeMake(0, 1.0)];
[self.layer setShadowRadius:1.0];
[self.layer setShadowOpacity:.15];
self.layer.shouldRasterize = YES;
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
}
I tried this but didn't work:
[self.tabSegment applyShadow];
It is not the best answer but try adding UISegmentedControl to a UIView as a subview. But be careful about setting the frames of each other the same.
Adding a UIView behind the Segment bar didnt work out for me, so I did find a quick solution to it, I added a UIView below the segment bar and applies shadow to it.If anyone come up with a better solution,I always welcome them.
self.shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1)];
self.shadowView.backgroundColor = [UIColor whiteColor];
[self.shadowView applyShadow];
[self.view addSubview:self.shadowView];

Add image to view (background)

I have added an image to my viewcontroller in code. Without the use of an imageview. This is how i did it:
UIImageView *backgroundImage =[[UIImageView alloc] initWithFrame:CGRectMake(50,50,100,500)];
backgroundImage.image=[UIImage imageNamed:#"backgroundImage"];
[self.view addSubview:backgroundImage];
There are 2 things i need a litte help with. How can i get the image to the back of the view, behind the labels, buttons etc.
And how do i get the image to fit all iphone screen sizes?
I hope you can help me.
Much thanks
As you asked two questions-
Question 1 : How to get the labels/ buttons other subviews visible over the image?
Answer -
Just add image before any other subview.
And there are two ways to set a background image to a UIView –
You can set your view background color to color created with UIColor’s colorWithPaternImage.
You can add a UIImageView subview to your view.
colorWithPaternImage was created to use small images to create a pattern image that will be repeated. Using it with large images wont be a wise decision. So if you want to have a patterned image background with uses small images which will be repeated to fill the background, then you should use colorWithPaternImage, as it will do it quickly and wont consume much memory.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background"]];
If you have a full size background image, then you should definitely use the UIImageView. Using UIImageView will save a lot of memory in this case.
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background"]];
[self.view addSubview:backgroundView];
Question 2 : How to show the image as per the device/ screen resolution?
Answer -
CGRect screenBounds = [[UIScreen mainScreen] bounds];
Use the above screenBounds to set the frame of ImageView.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"backgroundImage"]];
Just replace your code with this :
UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
backgroundImage.image = [UIImage imageNamed:#"backgroundImage"];
[self.view insertView:backgroundImage atIndex:0];
Hope this helps. Let me know it.. :)
Simply get screen size of device by following method to make it compatible to all device.
CGRect rect = [UIScreen mainScreen].bounds;
create UIImageView object of that frame size and insert at index 0 of UIView.
UIImageView *backgroundImage =[[UIImageView alloc] initWithFrame:rect]; // This will set image fit to all iphone...
backgroundImage.image=[UIImage imageNamed:#"your_image.png"];
[self.view insertSubview:backgroundImage atIndex:0];
UIImageView *backgroundImage =[[UIImageView alloc] initWithFrame:self.view.bounds]; // This will set image fit to all iphone...
backgroundImage.image=[UIImage imageNamed:#"your_image.png"];
[self.view addSubview:backgroundImage];
// This line will send image behind all the other controls
[backgroundImage sendSubviewToBack:self.view];

How to add border inside UIButton in iOS sdk?

I am using following code for adding border for UIButton,it works fine,But the border appears outside UIButton area.How to add border inside UIbutton area.Please help me..
[[button1 layer] setBorderWidth:7.0];
[[button1 layer] setBorderColor:[UIColor redColor].CGColor];
There is no direct way of adding an inner border for a UIView. However, you can add a subview to it. Something like this: (Implement the below method in your .m file).
-(void)setInnerBorderFor:(UIView *)aView withFloatVal:(CGFloat)aFloatVal
{
UIView *borderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aView.frame.size.width, aView.frame.size.height)];
borderView.backgroundColor = [UIColor clearColor];
borderView.layer.borderWidth = aFloatVal;
borderView.layer.borderColor = [UIColor blackColor].CGColor;
[aView addSubview:borderView];
}
And then, you can call :
[self setInnerBorderFor:button1 withFloatVal:7.0f];
I always use your same method to draw borders.
If you want to draw borders inside you could use a background image.
[button1 setBackgroundImage:[UIImage imageNamed:#"button1_bckg.png"]
forState:UIControlStateNormal];

mpmovieplayer not setting background in ios6

This code does not set the background view of a MPMoviePlayerController in iOS6 but works perfectly in iOS7.
UIView *patternView = [[UIView alloc] initWithFrame:self.view.bounds];
patternView.backgroundColor = [UIColor redColor];
UIImageView *imgView=[[UIImageView alloc]initWithFrame:self.view.bounds];
imgView.image=imgBackGround;
[patternView addSubview:imgView];
[self.moviePlayer.backgroundView addSubview:patternView];
What is the alternative?
You are ultimately setting the view with background color red.If you only wants set the background color,then instead of taking any view and adding it, set its MPMoviePlayerController view's background color directly.
[self.moviePlayer.view setBackgroundColor:[UIColor redColor]];

Shadow under UIActivityIndicator on iPhone/iPad

I want to create shadow under animated UIActivityIndicator to display that other ui elements are inactive, like shadow under keyboard or alert-view. What is the best way to do this?
Add a view with a black background and opacity to 50% with something like this :
UIView *shadowView = [[UIView alloc] initWithFrame:yourFrame];
[shadowView setBackgroundColor:[UIColor blackColor]];
[shadowView setOpacity:0.5];
[yourCurrentView addSubview:shadowView];
[yourCurrentView bringSubviewToFront:yourActivityIndicator];

Resources