For showing status bar in iOS 7 did the following code :-
- (void) viewDidLayoutSubviews
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0"))
{
CGRect viewBounds = self.view.bounds;
CGFloat topBarOffset = self.topLayoutGuide.length;
viewBounds.origin.y = topBarOffset * -1;
self.view.bounds = viewBounds;
}
}
As you can see in the image status bar color changes for both iOS Simulator 3.5 inch (iPhone 4/4s) and 4 inch (iPhone 5) .I want to show my status bar color white in 3.5 inch screens also. So, Please help me out from this issue.
Thanks in advance.
Go in your PLIST, and add this flag:
View controller-based status bar appearance = NO
next, in your AppDelegate in didFinishLaunchingWithOptions add this:
[[ UIApplication sharedApplication ] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES ];
after checking if your device is ios7. UIStatusBarStyleLightContent is new.
Hope this helps.
Related
I had tried following code to set background image of UINavigationBar.
It was working fine before Xcode 9 but in Xcode 9 image are not set properly.
UIImage *image = [UIImage imageNamed:#"headr_bg"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
Xcode 9 image 1
Xcode 9 image 2
[before Xcode 9]
may be its not perfect solution &
but i had old project in that i had fixed it by below code. Just updated navigation bar position and navigation view frame for ios version > 11.
CGRect navbarFrame = self.navigationController.navigationBar.frame;
CGRect navFrame = self.navigationController.view.frame;
navbarFrame.size.height = 44;
navFrame.origin.y = 20;
self.navigationController.navigationBar.frame = navbarFrame;
self.navigationController.view.frame = navFrame;
I had the same issue however I could not find a fix working with insets or with a layout based approach. Ultimately a quick work around was to create a secondary background image and pad the top of the original background with 20px with the previous color of your status bar (black in your case).
Then I simply added code to change the image depending if this is iOS 11+ like so:
NSString* navBarImg = #"navbar.png";
if (#available(iOS 11.0, *)) {
navBarImg = #"navbar_ios11.png";
}
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:navBarImg] forBarMetrics:UIBarMetricsDefault];
This may not work or may need tweaks depending if the status bar visibility is shown/hidden at some points. Hopefully this will help until a better approach is discovered.
I am developing iOs application using phonegap.
phonegap version : 3.5.0
xcode version : 6.1.1
I have added the "org.apache.cordova.statusbar" plugin for the status bar. My application is working fine on iOs 7 & iOs 8. But for better performance in iOs 8, I have added the "com.telerik.plugins.wkwebview" plugin. After adding this plugin, header part of application is destroy and looking that it is inside status bar. I have also attached image with this question. I have added the following property in my_project-info.plist file:
Status bar is initially hidden : NO
View controller-based status bar appearance : YES
You can solve this issue using following steps
1) Go to your project explorer, click on class folder there is file "MainViewController.m", add code
- (BOOL)prefersStatusBarHidden {
return YES;
}
2) Go to your project explorer, click on Resources folder there is file like "Your_project_name-Info.plist" add here as key View controller-based status bar appearance and value YES.
Find the "- (void)viewWillAppear:(BOOL)animated" method from MainViewController.m file and replace the method with following code.
- (void)viewWillAppear:(BOOL)animated
{
// View defaults to full size. If you want to customize the view's size, or its subviews (e.g. webView),
// you can do so here.
//Lower screen 20px on iOS 7 and iOS 8
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7){
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
}
[super viewWillAppear:animated];
}
This solution has worked for me.
When running my iPhone only app on an iPad with iOS 8 I've had a black bar appearing in my application's window. I can reproduce it reliably by backgrounding the app in landscape, then re-opening in portrait. Everything is fine on an iPhone.
To try and eliminate some extra factors I've replaced the initial viewcontroller in my storyboard with an xcode default new viewcontroller file. The black bar persists on my otherwise blank white window.
When the app is running "normally", the window looks to be padded with a grey area at the top. The black bar appears to "fall out" of this grey area and end up in the middle of my window.
I've tried setting "View controller-based status bar appearance" to NO. Then, adding the following to prefersStatusBarHidden gets rid of the annoying bar, but then my navbar gets cropped from the top!
- (BOOL)prefersStatusBarHidden
{
UIDeviceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
switch(orientation) {
case UIDeviceOrientationLandscapeLeft:
case UIDeviceOrientationLandscapeRight:
return NO;
default:
return YES;
}
}
I'm wondering if any of you know the cause/ cure for this?
See below for screen shots...
The Black bar!
App running normally, note padded grey area at the top of the screen.
I fixed my issues by...
Setting "View controller-based status bar appearance" to NO.
Testing for iOS version and setting my NavBar background image accordingly...
NSString *version = [[UIDevice currentDevice] systemVersion];
bool isAtLeastiOS_8 = [version floatValue] >= 8.0;
if(isAtLeastiOS_8) {
UIImage *bgImagePortrait = [UIImage imageNamed:#"NavBarPortrait.png"];
[self.navigationBar setBackgroundImage:bgImagePortrait forBarMetrics:UIBarMetricsDefault];
} else {
UIImage *bgImagePortrait = [UIImage imageNamed:#"NavBarPortrait.png"];
UIImage *bgImageLandscape = [UIImage imageNamed:#"NavBarLandscape.png"];
[[UINavigationBar appearance] setBackgroundImage:bgImagePortrait
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:bgImageLandscape
forBarMetrics:UIBarMetricsLandscapePhone];
}
Accepting the loss of the status bar in landscape mode on iOS 8
I had a similar problem: iPhone apps showing a black bar in landscape on retina iPads. It only happens if I use
- (BOOL) prefersStatusBarHidden { return NO; }
to override iOS 8's default behavior of hiding the status bar in landscape.
The black bar on mine is always 300x20 points in size (e.g., the size of the status bar in portrait, minus a 20-pixel-wide chunk) and has an alpha of around 0.9. It appears to be the mask that the iPhone emulation mode on the iPad uses for the iPhone app's portrait-mode status bar area (!); if I don't override iOS 8's preference, so there is no status bar in landscape, it works fine. It looks to me like a bug in iOS 8's iPhone emulation on iPad... just one more in a long line of iOS 8 bugs... :-(
My "fix" is to turn off the status bar only on iPads running iOS 8+:
- (BOOL) prefersStatusBarHidden {
if ([[[UIDevice currentDevice] model] hasPrefix:#"iPad"] &&
(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)) {
return YES;
}
else return NO;
}
I am unable to get the UISearchBar to display fine on iOS7. I cannot use AutoLayout as I must support the app for older versions of iOS prior to 6 also. I tried setting the container view's frame if the iOS is of version 7 and above but it does not work. I also tried topLayOutGuide length and other tips mentioned in other SO posts but I could not succeed. (EDIT:- I am using STORYBOARD)
The only thing I currently have in my code is
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0")) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
Can someone please help me with this issue?
I try to suggest a change to do in the storyboard:
tap on your viewController and on attributes inspector uncheck Under top bars
if this not work try this code:
-(void)viewWillAppear:(BOOL)animated {
NSString *ver = [[UIDevice currentDevice] systemVersion];
int ver_int = [ver intValue];
if (ver_int < 7) {
}
else {
self.navigationController.navigationBar.translucent = NO;
}
}
I have a iphone app which is installed in iPad its UI(blank space about 20 pixels above navigation bar) is correctly displayed in ios6 while a blank space appears in ios7 in iPad.
I tried using the default images and using the methods
- (void) viewDidLayoutSubviews {
if (([[UIDevice currentDevice].systemVersion floatValue] >= 7.0)) {
CGRect viewBounds = self.view.bounds;
viewBounds.origin.y = -20;
self.view.bounds = viewBounds;
}
}
but no use.How do i fix it? It is not a universal app.
The problem is related on the way iOS7 draws the views, please rewfer to these guide to understand the problem:
Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7