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
Related
i want to see which view is offscreen-rendered in my app.So i use the iOS simulator's 'color offscreen-rendered' function,it can color those offscreen-rendered view by yellow color.But after the app launched,the whole screen is colored by yellow and i don't believe it.
Then i try my test code like:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[UITabBarController alloc] init];
// self.window.rootViewController = [[UINavigationController alloc] init];
// self.window.rootViewController = [[UIViewController alloc] init];
[self.window makeKeyWindow];
}
As you can see above,i simply set the window's rootViewController three times different by orginal controllers: 'UITabBarController','UINavigationController' and 'UIViewController'.
Guess what?
Only the 'UIViewController' is not whole screen colored!!!
So anyOne knows why the orginal rootViewController and UINavigationController will occur the whole screen offscreen-render??????
It's because default translucent value of UITabBar and UINavigationBar are YES.
You should check Apple documents for UINavigationBar.translucent and UITabBar.translucent for more information.
A small demo by creating a UINavigationController with a red background root view controller, we can compare the difference when translucent is YES and NO.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
UIViewController* viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [UIColor redColor];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
// nav.navigationBar.translucent = NO;
self.window.rootViewController = nav;
[self.window makeKeyWindow];
return YES;
}
By default, translucent is YES. So you can see background of UINavigationBar has a little red.
Color offscreen-rendered
But when we set translucent to NO. No more red in background of UINavigationBar.
Color offscreen-rendered
We have transparent here so that's why screen is colored. You can try similar thing with translucent of UITabBar.
To avoid offscreen-rendered with UINavigationController and UITabBarController, you should set this property to NO.
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];
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.
I've just started to make a new app with a navigation bar. I made the first view with the navigation in the AppDelegate.m.
AppDelegate.m :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
sleep(2);
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:[[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil]];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
Then, I making the view of the HomeViewController inside loadView method.
LoadView of HomeViewController :
- (void)loadView
{
self.view = [[UIView alloc] init];
self.view.backgroundColor = [UIColor whiteColor];
self.searchPoiInstructionsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 20)];
self.searchPoiInstructionsLabel.layer.borderColor = [UIColor blackColor].CGColor;
self.searchPoiInstructionsLabel.layer.borderWidth = 2.0f;
self.searchPoiInstructionsLabel.text = #"HELLO WORLD";
[self.view addSubview:self.searchPoiInstructionsLabel];
}
My label Hello World doesn't appear...
For the frame, if I set CGRectMake(0, 65, 50, 20) , 65 for y, my "Hello World" appears... (I know, I have to increase the width :) )
I just don't understand the origins of my view... If someone can explain me please.
Thanks
This is iOS7 baggage. If you run your app under iOS6, you will see the label as you expect/intend.
Under iOS7, your view originates under the navigation bar which is why you don't see the label when you set the frame to originate at 0,0. If you look really closely, you can actually see the blurred label behind the Carrier indicator in the status bar.
There are multiple ways to work with this:
If the UINavigationBar is not translucent, then the 0,0 origin will work.
You can update the labels frame using topLayoutGuide
You could use a UIScrollView instead of UIView
Origin in iOS 7 is kind of different. In a Navigation Controller, things below Navigation bar can be showed a little with blur effect. So the label's origin in the Navigation Controller is up-left (0, 0) point below the Navigation bar instead of the leftest point under the Navigation bar. Here a demo for you.
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[[[UIDevice currentDevice]systemVersion] componentsSeparatedByString:#"."][0] intValue] >=7) {
if ([self respondsToSelector:#selector(edgesForExtendedLayout)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
}
}
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.