UINavigationBar appearing as semi-translucent instead of opaque white - ios

This is in an app I'm converting from iOS 6. Initially the ViewController was showing up under iOS 7 with the content of the main view underneath the navigation bar.
In the UI builder view, I turned off "Under Top Bars" and "Under Bottom Bars" in the "Extend Edges" section, to solve that issue. This worked, however, now on this screen the navigation bar appears to be translucent (comes across as grey in the screenshot below).
I've tried explicitly setting "Top Bar" to "Opaque Navigation Bar" under "Simulated Metrics," but this has no effect.
I've tried setting:
self.navigationController.navigationBar.translucent = NO;
in my ViewController's init code, but this also has no effect.
What am I missing?
UPDATE: If I set self.navigationController.navigationBar.translucent = NO; in my first ViewController in the stack, it works. However, prior to the ViewController in question, I do want translucent navbar. It's only when I get to a view several layers deep that I want to have a non-translucent bar (this view has no scrollable data, so it doesn't make sense to have it translucent).
Here's a screenshot of what I'm seeing in the nav bar:

The issue was that I was calling
self.navigationController.navigationBar.translucent = NO;
after my view appeared. I moved that code into my viewWillAppear method, and now it appears correctly:

You can try below code...
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
self.navigationController.navigationBar.translucent = NO;
And Add this code in View viewDidLayoutSubviews function...

You can set it across the board with an app using this:
UINavigationBar.appearance().navigationBarAppearace.translucent = false
I tend to do it in my AppDelegate class when the app initially loads up.

all you need to do for iOS6 is to set the controller's fullscreenlayout to NO and then PUSH it to your NavigationController
[controller setWantsFullScreenLayout:NO];

Related

When the UITabbar is Translucent and the UIViewController is not extended behind the tabbar, the uitabbar seems like covering a black view

The tabbar in first view is what I want. Because the second view isn't a scrollview, so I can't extend it to bottom by using self.edgesForExtendedLayout = UIRectEdge.Bottom.
It looks unacceptable.
And I don't want to set Translucent of uitabbar to false, it's not fancy.
I try in another way:
[[UITabBar appearance] setBarTintColor: [UIColor whiteColor]];
It doesn't work. To make it looks more clear, I change the color to red. And the last tabbar also looks like covering some black views.
Consider of the tabbar is translucent, what's the view under the UITabbar view?
This is the final answer of why it doesn't work when changing the tintcolor of bar. Because the view under UITabbar view is black.
Thanks to the Xcode awesome debugging function. We could locate the view under UITabbar view easily.
It's UIWindow. So the solution is to simply change the window's backgroundColor to white.
I would say that adding this code in viewDidLoad of your viewController will solve your issue:
edgesForExtendedLayout = .all
extendedLayoutIncludesOpaqueBars = true
Plus you can keed your tabBar translucent and not set any background color.

iOS 7 Navigation Bar does not stay clear

I want to have my navigation bar clear in iOS 7. I know this question has been asked before, but I cannot find an answer to the specific problem that I am having. I set my navigation bar clear in my App Delegate using this code:
UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
navigationBarAppearance.backgroundColor = [UIColor clearColor];
[navigationBarAppearance setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
navigationBarAppearance.shadowImage = [[UIImage alloc] init];
That works fine, my first navigation bar is clear. Then when I select a button and push a new view controller it gets a slight alpha increase on it. Looks like black with about 20% alpha. See picture here:
Then when i press the back button, the first view has the same slight alpha increase affect on it.
I have commented out ALL references to navigation bar in the second view controller to make sure I'm not accidentally changing something. I checked for differences in IB between the first and second view controllers and can't find anything there either. Tearing my hair out!
try setting the translucent property to YES in viewDidAppear
navigationBarAppearance.translucent = YES;
try this !
navigationBarAppearance.layer.backgroundColor = [UIColor clearColor].CGColor;
As expected I was missing something in the code!
The view controller inherited from a custom view controller class that was setting an alpha onto the navigation bar.

iOS 7 | Navigation bar / Toolbar buttons very close to status bar

I have a problem when dragging a navigation bar or toolbar (storyboard) to my view controller.
UINavigationBar:
As you can see in the image above, the right button is almost overlapping the status bar.
With a UIToolbar it happens the same:
This view controllers are intended to be used as a Modal, that's the reason I'm not using a UINavigationController.
In another section I use a UINavigationController and it appears as I expect:
How can I drag a UINavigationBar / UIToolbar to a view controller without overlapping the status bar?
The navigation bars or toolbars have to be at (0, viewController.topLayoutGuide.length) with bar positioning of UIBarPositionTopAttached. You should set the delegate of your navigation bar or your toolbar to your view controller, and return UIBarPositionTopAttached. If positioned correctly, you will have the result in your third image.
More information here:
https://developer.apple.com/documentation/uikit/uibarpositioningdelegate?language=objc
Do these steps
Drag the NavigationBar to your ViewController in Xib, set the ViewController as its delegate.
Note that the NavigationBar should be at (0, 20)
In ViewController, conform to the UINavigationBarDelegate
#interface ETPViewController () <UINavigationBarDelegate>
Implement this method
- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar
{
return UIBarPositionTopAttached;
}
positionForBar tells the NavigationBar if it should extend its background upward the Status Bar
Please see my answer here, I've copied the content below for convenience:
https://stackoverflow.com/a/18912291/1162959
The easiest workaround I've found is to wrap the view controller you want to present inside a navigation controller, and then present that navigation controller.
MyViewController *vc = [MyViewController new];
UINavigationController *nav = [[UINavigationController alloc]
initWithRootViewController:vc];
[self presentViewController:nav animated:YES completion:NULL];
Advantages:
No mucking with frames needed.
Same code works on iOS 6 an iOS 7.
Less ugly than the other workarounds.
Disadvantages:
You'll probably want to leave your XIB empty of navigation bars or toolbars, and programatically add UIBarButtonItems to the navigation bar. Fortunately this is pretty easy.
You can resolve this issue by using Auto Layout, as per this techincal note (Preventing the Status Bar from Covering Your Views).
Here are some excerpts:
Add the Vertical Space Constraint to the top-most view
Control drag from the UIToolbar to the "Top Layout Guide"
In the popover, choose "Vertical Spacing"
Change the "Vertical Space Constraint" Constant to 0 (zero)
If you have other subviews below the UIToolbar, anchor those views to
the toolbar instead of the Top Layout Guide
This will support ios6 and ios7.
You can also manage it by increasing height of navigation bar by providing image of size 620x128 for ios version. And this image is used in :
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)?YES:NO) {
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"newImage.png"] forBarMetrics:UIBarMetricsDefault];
}else{
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"previousImage.png"] forBarMetrics:UIBarMetricsDefault];
}
I gave up and had to set the navbar height constraint to 64 in x xib based VC cause viewController.topLayoutGuide.length is 0 in viewDidLoad despite statusbar being present :-[
which means in a non universal app on ipad you'd have 20 px on the top of the
view wasted (cause status bar is separate from the iphone simulation window)

How to prevent UINavigationBar from covering top of view in iOS 7?

After updating to Xcode 5, the navigation bars in all of my app's views have shifted down. Here are some screenshots, the first showing everything in the view as it's pulled down, and the second showing all of it untouched. The search bar should begin where the navigation bar.
Anyone know how I can fix this?
edit: i have tried this previously recommendation:
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
But it yields very odd results.
This may be because I have a "slide menu" under this view controller that is appearing due to the transparency of the navigation bar.
Set the navigation bar's translucent property to NO:
self.navigationController.navigationBar.translucent = NO;
This will fix the view from being framed underneath the navigation bar and status bar.
If you have to show and hide the navigation bar, then use
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone; // iOS 7 specific
in your viewDidLoad method.
In iOS 7 by defaults all Controller translucent property value is YES, so you set translucent property NO for this issue.
self.navController.navigationBar.translucent = NO;
You can disable
the "Extend edges" in Attribute inspector of View Controller of this screen (as shown in below image)
:
This works for swift as well on iOS 8.1
navigationController?.navigationBar.translucent = false
If you want to keep the translucency on your navigationBar, at the end of your viewDidLoad or in your viewWillAppear add this line of code:
[self.view sendSubviewToBack:self.tableView]
Somehow if your scrollView subclass (UITableView, UICollectionView, etc.) is at index 0 in your current view subviews, it will automatically adjust the insets according to your navigationBar. And it shouldn't affect your UI in versions prior to iOS7 either.
EDIT
If you initialize your UITableView programmatically, then it is best to add it to the view using this [self.view insertSubview:self.tableView atIndex:0];
Swift 4:
Set following line of code in viewDidLoad method:
self.navigationController?.navigationBar.isTranslucent = false
You can add this method into your view controller as shown on this URL:
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.searchBar.frame =
CGRectMake(0, self.topOfViewOffset, self.searchBar.frame.size.width, self.searchBar.frame.size.height);
}
Another approach is to set self.automaticallyAdjustsScrollViewInsets = YES; on your view controller.
This is enabled by default. But in your case:
I see you are using EGORefreshHeaderView. It plays with contentInset of UITableView. So when you release it, header will reset top inset instead of restore previous value.
If you want to have complete control on views and avoid faulty adjustments of iOS, subclass UITableView and adjust the insets (both scroll and indicators) in -(void)willMoveToWindow:(UIWindow *)newWindow. Works for me.
Another option is to open your Info.plist file in source code mode and enter the following info:
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIStatusBarHidden</key>
<true/>
Hope this helps.

iOS 7 status bar transparent

In storyboard, in a view controller I tried add a navigation bar under the status bar, running it, it is transparent and shows a label that's supposed to be blurred, like by navigation bar.
But when placing the same view controller embedded in a navigation view controller, the underneath background image could be blurred, which is my intention.
What are these two way different results? What need to do for the firs method to make status bar blur?
Thanks!
In iOS 7 the status bar is transparent by default. The blurring you're seeing when there's also a navigation bar is actually created by the navigation bar. So to create the effect you're looking for without a navigation bar, you need to position a view that produces a blurring effect beneath the status bar.
For reference, add your view with a frame provided by:
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
I know this is old, just for reference, I solved this by setting self.navigationController.navigationBar.clipToBounds = NO
I haven't tested this completely, but go to your plist file and check the following settings:
"View controller-based status bar appearance": If this is set to "Yes", then it should display a status bar that is unique to each View Controller, which might be what you need.
"Status bar style": You may set this to three different styles: Opaque black, Gray, and Transparent black.
Let me know if this worked for you.
UINavigationController will alter the height of its UINavigationBar to either 44 points or 64 points, depending on a rather strange and undocumented set of constraints. If the UINavigationController detects that the top of its view’s frame is visually contiguous with its UIWindow’s top, then it draws its navigation bar with a height of 64 points. If its view’s top is not contiguous with the UIWindow’s top (even if off by only one point), then it draws its navigation bar in the “traditional” way with a height of 44 points. This logic is performed by UINavigationController even if it is several children down inside the view controller hierarchy of your application. There is no way to prevent this behavior.
It looks like you are positioning your view hierarchy in the first example starting at the point (0,20). Also, is that a UIToolbar or a UINavigationBar? If it's the latter, why are you using it by itself and not using it inside of UINavigationController?
If you do not use UINavigationController and are instead using custom view controller containers, you'll need to position your views accordingly.
See this answer for a thorough explanation.
I have similar UI design and based on Matt Hall answer and some article I've googled, I come up with something like this:
- (void)viewDidLoad {
[super viewDidLoad];
if (NSFoundationVersionNumber>NSFoundationVersionNumber_iOS_6_1) {
CGRect statusBarFrame = [self.view convertRect: [UIApplication sharedApplication].statusBarFrame fromView: nil];
UIToolbar *statusBarBackground = [[UIToolbar alloc] initWithFrame: statusBarFrame];
statusBarBackground.barStyle = self.navBar.barStyle;
statusBarBackground.translucent = self.navBar.translucent;
statusBarBackground.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
[self.view addSubview: statusBarBackground];
}
}
Where self.navBar points to navigation bar added in storyboard. This is needed only in case when it runs on iOS7 that is why I've added this condition (my app has to support iOS5).
This works like a charm.
alternative approach (enforce status bar size) is also good:
- (void)viewDidLoad {
[super viewDidLoad];
if (NSFoundationVersionNumber>NSFoundationVersionNumber_iOS_6_1) {
CGRect statusBarFrame = [self.view convertRect: [UIApplication sharedApplication].statusBarFrame fromView: nil];
self.navBar.frame = CGRectUnion(statusBarFrame, self.navBar.frame);
}
}
I've found another solution I think this is best since it involve only storyboard and no code is required.
Switch storyboard view to 6.1 mode (view as: iOS 6.1 and Earlier)
Select problematic UINavigationBar
in size section add 20 delta height in "iOS6/7 Deltas"
Switch back view to 7.0 mode (view as: iOS 7.0 and Later), and be happy with result.
when you embed view controller with navigation view controller that time you will see navigation bar to all the view controller you are pushing to from same view controller. In your first case you are adding the navigation bar object, insted of that you can select view controller from storyboard , go to attributes inspector tab & from their select Top bar as translucent navigation bar.

Resources