Show custom view over tab bar in iOS - ios

I want to show custom view over tab bar. I have seen that UIAlertView shows view over UITabBar and user can't interact with tab bar when alertView is open. I tried it by showing it over the keyWindow by using the code below:
[[[UIApplication sharedApplication] keyWindow] addSubview:myViewObject];
but user can still change the tabs.

I used to do it with overlayView when I create custom controls that need to block the block whole window and show
//self refers to active UIViewController
UIView *overlay =[[UIView alloc]initWithFrame:self.view.window.rootViewController.view.bounds];
overlay.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.4];
overlay.tag = 1001;
[overlay setUserInteractionEnabled:YES];
[self.view.window.rootViewController.view addSubview:overlay];
you can add a tap gesture to remove overlayView from superview .

try this out:
UIView *coverView = [[UIView alloc] initWithFrame:self.view.frame];
coverView.backgroundColor = [UIColor greenColor];
coverView.alpha = .3f;
UIWindow *window = [[UIApplication sharedApplication] windows].lastObject;
[window addSubview:coverView];

You can set tabBarController.tabBar.userInteractionEnabled = false on the tab bar while the custom view is shown.

Related

How to add a subview to cover UINavigation barin UIViewController?

Hello I want to add a UIViewon top of my current view controller. So I did like this.
- (void)viewDidLayoutSubviews
{
UIView *vwOverlay=[[UIView alloc] initWithFrame:self.view.frame];
[vwOverlay setBackgroundColor:[UIColor blackColor]];
[vwOverlay setAlpha:0.5];
[self.view addSubview:vwOverlay];
}
but this is adding top of my view but behind my navigation bar.Istill can clearly see navigation bar title and navigation menu items and also can click navigation bar items. But I want to cover this navigation bar too from my new view.
How can I do this? Please help me.
Thanks
Use this code
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
CGSize screenBounds = [UIScreen mainScreen].bounds;
UIView *vwOverlay=[[UIView alloc] initWithFrame: screenBounds];
[vwOverlay setBackgroundColor:[UIColor blackColor]];
[vwOverlay setAlpha:0.5];
[window addSubview:vwOverlay];

UITableView background does not set

I have this code inside the viewDidLoad (putting that inside the viewDidAppear didn't work either).
UIView *texturedBackgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
texturedBackgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BackgroundLeather.png"]];
self.tableView.backgroundView = texturedBackgroundView;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
But I cannot see any background as an image. It is completely white - like no image is set. Why is that?
Please note that, my tableview has it's own controller - which is initialised like this :
AppDelegate *del = (AppDelegate*)[[UIApplication sharedApplication] delegate];
PAPHomeViewController *vc = del.homeViewController;
vc.view.frame = self.containerView.bounds;
[self.containerView addSubview:vc.view];
[self addChildViewController:vc];
So, it is like I see the background of the containerView and not the background of the tableview.
Trying that didn't help it :
[self.containerView setBackgroundColor:[UIColor clearColor]];

Control Nav Bar Tints with PSPDF

Hi I have a PSPDFViewController embedded in a UINavigationController which I then have as the left controller in a splitview controller.
I have set the colour of the navbar to match the right hand controllers nav bar however it seems PSPDFKit is changeing the colour or alpha slightly. Is there any way I can turn this off?
Here is how I'm creating the controller:
PSPDFViewController *pspdfController = [[PSPDFViewController alloc] initWithDocument:document];
UINavigationController *pspdfNavigationController = [[UINavigationController alloc] initWithRootViewController:pspdfController];
pspdfNavigationController.barTintColor = [[UIColor alloc] initWithRed:252.0/255.0 green:14.0/255.0 blue:47.0/255.0 alpha:1.0];;
pspdfNavigationController.backgroundColor = [[[UIColor alloc] initWithRed:252.0/255.0 green:14.0/255.0 blue:47.0/255.0 alpha:1.0];
pspdfNavigationController.tintColor = [UIColor whiteColor];
navbar.translucent = NO;
Lulz:
self.transparentHUD = NO;

Put status bar under view

Here you can see, that the status bar is above the black background. How to put status bar under it? Like you can see the navigation bar is.
I need to get something like this:
this is possible if you create new window and add that view to it.
Make a window property in your ViewController as shown below
#property (nonatomic,strong) UIWindow *window;
And write below code in viewDidLoad
self.window =[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor =[UIColor blueColor];
self.window.alpha =0.5;
UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.backgroundColor =[UIColor greenColor];
[self.window addSubview:view];
self.window.hidden =NO;
self.window.windowLevel =UIWindowLevelStatusBar; // it works with window level as UIWindowLevelAlert
[self.window makeKeyAndVisible];
Hope this helps.
Try this code:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
This will hide the status bar.
See the whole post here

How do I add a dark screen that covers all other views (including navigation bar and status bar)?

I want to add a dark screen over all my views, and then present a notification window above it, like in Tweetbot 3:
However, I'm not totally sure how this is accomplished.
Adding a dark view with the size of the screen as its frame does not work, as below: (navigation bar and status bar aren't covered)
UIView *darkOverlay = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
darkOverlay.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
[self.view insertSubview:darkOverlay behindSubview:self.view];
This covers everything except the status bar (so it comes pretty close, but as I have light status bar content it's still very jarring):
[[[UIApplication sharedApplication] keyWindow] addSubview:darkOverlay];
So how is something like this accomplished?
You can try this method
UIWindow* window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.windowLevel = UIWindowLevelAlert;
window.opaque = NO;
[window addSubview:someView];
// window has to be un-hidden on the main thread
[window makeKeyAndVisible];
Where "view" - is your custom popup.
You have to do this:
CGRect screenRect = [[UIScreen mainScreen] bounds];
_darkCoverView = [[UIView alloc] initWithFrame:screenRect];
_darkCoverView.backgroundColor = [UIColor blackColor];
_darkCoverView.alpha = 0.5;
[[[[UIApplication sharedApplication] delegate] window] addSubview:_darkCoverView];
It works for me, and the status bar is covered as well :)
You can try to simply present it modally, as modal view controllers go above nav controllers.
TransparancyViewController *vc=[[TransparancyViewController alloc]initWithNibName:#"TransparancyViewController" bundle:nil] ;
vc.view.backgroundColor = [UIColor clearColor];
navController.view.alpha = 0.3;
navController.modalPresentationStyle = UIModalPresentationCurrentContext;
[navController presentViewController:vc animated:NO completion:nil];
Small sample project for using with Storyboards.. http://cl.ly/442C11341k2G
When you create the darkOverlayView it may be better to specify the actual bounds of the view, which should fill the whole screen (width,height for iPhone 5 used).
UIView *darkOverlay = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 568)];
If your notification object is also a UIView, bring this to the front.
[self.view addSubView:darkOvelay]
[self.view bringSubviewToFront:notificationView];
I hope this solves your problem, cheers, Jim.

Resources