Shadow under UIActivityIndicator on iPhone/iPad - ios

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];

Related

Is it possible to dim a UIView but allow touch of elements behind it?

How would you have a grey overlay on top, but allow to touch buttons beneath it?
You can set userInteraction of overlay to false.
As mentioned, you can set userInteractionEnabled to NO.
But pay attention: when you create a full screen transparent view, and set its userInteractionEnabled to NO, all the subviews of that view will not be responsive to user actions. If you add a button on your view, it will not respond to user taps! and another problem: if you set the alpha value of that view to be transparent, e.g. 0.4, then all its subviews will be transparent too!
The solution is simple: don't put any subview on your transparent view, but instead, add your other elements as siblings of your view. Here is Objective-C code to show what I mean: (notice the comments which say it all):
//Create a full screen transparent view:
UIView *vw = [[UIView alloc] initWithFrame:self.view.bounds];
vw.backgroundColor = [UIColor greenColor];
vw.alpha = 0.4;
vw.userInteractionEnabled = NO;
//Create a button to appear on top of the transparent view:
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 80, 44)];
btn.backgroundColor = [UIColor redColor];
[btn setTitle:#"Test" forState:UIControlStateNormal];
[btn setTitle:#"Pressed" forState:UIControlStateHighlighted];
//(*) Bad idea: [vw addSubview:btn];
//(**) Correct way to have the button respond to user interaction:
// Add it as a sibling of the full screen view
[self.view addSubview:vw];
[self.view addSubview:btn];

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]];

Resize background color/image base on new UIView's size?

How to make the view's background color change base on the size of view? I can re-size the view but seem the background color not change, it's fixed.
color = [view backgroundColor];
[view setBackgroundColor:[UIColor clearColor]];
[view setFrame:rect];
[view setBackgroundColor:color];
You have set the background color of view to ClearColor , So it's not being changed.
Try,
color = [view backgroundColor];
[view setBackgroundColor:[UIColor clearColor]];
[view setFrame:rect];
// here you need to set the
color = [UIColor redColor]; // or the color you want to change
[view setBackgroundColor:color];
Implement the setFrame Method of the View then only Your Change background color will be called when ever you change the size of View....
Make subclass of a UIView and implement setFrame Method.
-(void)setFrame:(CGRect)frame{
self = [super setFrame:frame];
self.backgroundColor = [UIColor redColor];
//Put any condition here for specific background color using frame property of view
}

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)];

Resources