Mughees Musaddiq
Mughees Musaddiq

Reputation: 1060

Show custom view over tab bar in 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.

Upvotes: 2

Views: 4434

Answers (3)

Irfan Gul
Irfan Gul

Reputation: 1577

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 .

Upvotes: 2

cuomo456
cuomo456

Reputation: 185

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

Upvotes: 0

Robert
Robert

Reputation: 3880

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

Upvotes: 1

Related Questions