I am trying to show a top bar in Xcode 9 Swift 4. In my storyboard it shows the top bar as in the below picture:
but when I run it I get this with no top bar:
I tried to use a navigation bar just with a title but it shows as:
the carrier, wifi, time, and battery background is still white. If I set the navigation bar to the top of the screen, it will cover them like:
Why the top bar is not showing? How can achieve something like this?:
UPDATE
Top bar is not a navigation bar. It is kind of just a bar that shows a title. As you can see in the below picture, the register scene doesn't have a navigation bar. I added the top bar from the properties on the right side.
In your second to last screen, where you show that the navigation bar covers it:
It does not really cover it - but the text of the status bar is black, so you cannot see it. To change it, in the implementation of the GrolocationNewsViewController (or whatever you call it) override preferredStatusBarStyle and return .lightContent:
class GrolocationNewsViewController: UIViewController {
// rest of the code
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
I have used the code from #Milan Nosáľ answer and it does show the status in white. Then used #Ameya Vichare answer on this link while I was looking for a way to increase the navigation bar height
How to change navigationBar height in iOS 11? turn out it is a bug in Xcode 9. Now it shows like what I wanted:
Related
I have a problem with my app development in Xcode 11.3. I'm developing an app targeting iOS 13.2, and I've edited the navigation bar so that its background is black. However, I can't seem to find a way to delete or hide the title bar. Now it just looks like a big black bar.
All the other content is served over a webview, so that's why I'd need to remove the title bar but not the black background color in the navigation bar (where the time and battery, etc. are displayed). I hope you can help.
Here's the preview currently:
Thanks!
So it sounds like you want something like this:
So, in that screen shot:
We're in a navigation interface, but the navigation bar is hidden.
The green view is a stand-in for your "Aleksis" view. Its top is pinned to the bottom of the safe area.
There is also a black view. Its top is pinned to the top of its superview (the view controller's main view) and its bottom is pinned to the bottom of the safe area. It is behind the green view.
Here's the storyboard configuration I used:
Here's the view controller code:
override var preferredStatusBarStyle: UIStatusBarStyle { .lightContent }
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = true
}
I've used UISearchController. When I click on the search bar, navigation bar hides and search bar goes to the top of the screen. But, it shows extra space between top of the screen and the search bar
How do I change statusBar color to default searchBar gray color ?
StatusBar font colour is white, hence when user click search bar, auto above status bar information becomes invisible.So i just need to cover that area by default gray color too, then user can see clearly the status bar.Like this
The extra space is your status bar which you is lost in your white background.
func viewDidLoad() {
super.viewDidLoad()
edgesForExtendedLayout = UIRectEdge.None
}
You can try one of following based on your implementation:
If you are using storyboards Click on the view controller or TableView Controller which you have set up for your tableview and go to its attribute inspector and look under ViewController section and set the Extend Edges section to be under Top Bars.
If you are not using storyboards set the settings using the viewcontrollers edgesForExtendedLayout property and that should do the trick.
Figured it out , just need to add this code to viewDidLoad :-
definesPresentationContext = true
I have a modally presented view controller which is not in the navigation stack but needs a navigation bar to cancel the selection. The VC is presented by another VC which is a popup (a real one not a fullscreen view). I need a navigation bar in it to present a title and a cancel-button in the upper right hand corner just like the standard camera roll image picker has it.
Here's what I tried so far:
I added the navigation bar manually by dragging it to the view in the storyboard and attached it with constraints. That works great but the problem is that the navigation bar is too small. It doesn't mind the status bar above it so the cancel button and the title are very close (almost overlapping) to the status bar.
Tried to increase the navigation bar's height but apple doesn't allow changing the frames of navigation bars.
Tried push it down a bit with constraints but that results in a white background color for the status bar since the controller has a white background.
Implemented a new navigation controller just for the one view that needs the bar. But that will give me a standard navigation bar with an arrow in the top left corner which doesn't really fit the navigation feeling since the view is presented modally (from the bottom). Also this seems to be a bit much overhead.
What can I do to achieve a camera-roll-like navigation bar?
BTW: I work with swift.
EDIT:
I tried this but setting the height value fails obviously since it's not allowed.
#IBOutlet weak var navigationBar: UINavigationBar!
override func viewDidLoad() {
navigationBar.frame.height = 44.0
}
I actually found a solution to this:
Set the VC as the delegate for the navigation bar
Conform to protocol UIBarPositioningDelegate
Implement
func positionForBar(bar: UIBarPositioning) -> UIBarPosition {
return .TopAttached
}
Push the navigation bar down with constraints by 20p
Voila
I want add 20 points margin to my navigation bar. I need it because I want another background color under status bar as youtube did:
I found
iOS Developer library says: Status bar background appearance provided by the window background, if using UIBarPositionTop.
I found solution for toolbar, but I can't move my navigation bar inside navigation view controller. I just set UIBarPositionTop for my navigation bar, but it changes nothing.
-(UIBarPosition)positionForBar:(id<UIBarPositioning>)bar {
NSLog(#"position method called");
return UIBarPositionTop;
}
I still see the gray background of status bar instead of white.
Is it possible to do it with a navigation bar or should I use a view with a toolbar?
(XCode 6, development target 7.0+, sdk 8.0, autolayout)
UPDATE: ANOTHER WAY TO RESOLVE PROBLEM
I read this question
and understood, that there is no need to add margin. I added view with background color I need over my navigation bar controller and it resolved my problem.
When you are adding your UIView to the UIWindow, you should change the UIViews size to not underlap the title bar. How to do this is well documented in this post:
Offset on UIWindow addSubview
I hope i understood correctly, look in size inspector, ios 6/7 deltas.
Check this link for an explanation:
Interface Builder: What are the UIView's Layout iOS 6/7 Deltas for?
I embedded a navigation controller in a tab bar controller, the problem is that the navigation bar (with the blue color) get under the status bar. So the status bar appear transparent because it shows what is under. Here is a screenshot:
I tried to modify the status bar directly in Attributes Inspector to black and Translucent black, also disabled autolayout although i know it has nothing to do with such issue. Anyway, nothing is fixed. I used to work with that in iOS5, but since iOS6 and the new 4" storyboard screen, i got this issue.
There is a misunderstanding here. The navigation bar is not "under" the status bar. This is iOS 6's new color-adopting status bar. You can read more here.
If you do not like this behavior, your only option is to make the status bar black. Take a look at the project properties page.