Apple says in its Documentation:
It is permissible to customize the appearance of the navigation bar using the methods and properties of the UINavigationBar class but you must never change its frame, bounds, or alpha values or modify its view hierarchy directly.
They never strictly mention that changing constraints is not allowed but I'm assuming it falls under the same criteria as of changing the frame.
I would need this for a messages app in order to achieve the translucency effect under the iMessage standard top bar. What I currently have is a UINavigationController embedded in a MSMessagesAppViewController with the topAnchor set underneath the topLayoutGuide. This prevents me from achieving the effect but places the navigation bar below the top bar accordingly. If I set the constraints to just attach to the topAnchor, the Navigation bar is hidden in the extended view. Changing the constraints of the UINavigationBar here could solve the problem.
Am I allowed to change the constraints of the UINavigationBar and if not, any other solutions for this issue? For any further information just tell me.
I don't know how well anyone on Stack Overflow can answer this question, since it ultimately comes down to Apple's opinion/review. I've shipped apps with oversized/modified Navigation Bar and Navigation Controller frames without rejection from Apple, so I would tentatively say that this is safe to modify in your app.
I'm not sure what you're describing (as I don't know what MessagesController is), but it sounds like you have a Navigation Controller embedded inside another Navigation controller, and fixing the issue by hiding one of the bars sounds like a code smell...
Related
No matter what I do, the segue kind is always present modally (one vc on top an other). This is even when it is not set to it. At the moment my segue is set to "Show" but even still, the bar at the top of the view controller is still there and when I run the app it does the present modally over the top animation.
I don't know where to go from here!!
Reseting my computer.
Reinstalling Xcode.
Different ways of showing the vc.
This is what I mean by white bar at top
Update: I have seen your screenshot update to the question and I would like to point out that the issue that you are trying to solve has nothing to do with modal presentations. The content of the ‘view’ of a ‘UIViewController’ does not fill the screen because it’s constrained either to the Safe Area or the margins of the its superview.
Initial answer:
Lol but that’s a feature and not a bug. The “Show” setting that you are talking about only controlls the animation. In order to discard all instantiated modal presentation contexts you have to swap out the ‘rootViewController’ of the ‘UIWindow’ in which this contexts exist.
Please note that storyboard segues feature no support for this in UIKit.
Please note that usage of storyboard segues is an ill practice and should be considered deprecated. The primary reason for this is that it prevents programmer from establishing a proper routing layer in the application leading to a rapidly increasing technical debt.
The reason is that Show has a complex meaning. It means:
"If our parent is a UINavigationController, push. Otherwise, present modally."
Well, your parent is not a UINavigationController. There is no UINavigationController anywhere around! So Show ends up meaning exactly the same thing as Present / Modal.
I want a UINavigationBar at the top of my UIWebView but I want to control by hand the title, the back button, what the back button does - etc. In other words I never want to push or pop views. I just want to change the UINavigationBar contents as the user clicks around the web view.
Where I'm up to is I added the UINavigationBar to my superView and made it 44 pixels tall. How do I set the title since I have no navigationItem? How would I set a fake back button up?
I would appreciate any pointers. I realise this is quite weird what I'm doing.
Thanks :)
The answer, if anyone's interested, is in the class reference of UINavigationBar.
When you use a navigation bar as a standalone object, you are
responsible for providing its contents. Unlike other types of views,
you do not add subviews to a navigation bar directly. Instead, you use
a navigation item (an instance of the UINavigationItem class) to
specify what buttons or custom views you want displayed. A navigation
item has properties for specifying views on the left, right, and
center of the navigation bar and for specifying a custom prompt
string.
In short, use a UINavigationItem and apply it by "pushNavigationItem" on the UINavigationBar.
I created a subclass of UINavigationBar called StaticNavigationBar which I can then load with any state by putting the appropriate UINavigationItem's on it. Thanks for all your answers people.
You can have that UINavigationBar as an outlet and then you can manupulate it as you want. So you don't have to refer to somebody's navigation item. It'll be an independent (sort of) object on your view.
If you dont want the navigationbar as-is youll have to roll your own.
if youre ok with the built in animations for pushing and popping items(dont confuse with push/pop of viewcontrollers) to the bar you would then set your UINavigationBarDelegate and use its methods for controlling how things push/pop, etc.
I am developing app that has multiple skins and I have a dilemma on how to implement this.
One of the solutions would be to have separate nib files for every skin, and load it depending on which skin is currently selected. Problem with this is that I can't edit navigation bar of navigation controller (which my app uses), and I have to change it's background image and back button image etc.. I came up with an idea to hide this navigation bar on every screen and replace it with custom UIView in Interface Builder which will act as navigation bar and custom back button with IBAction for popping current View Controller, so that user won't see any difference.
Is this approach acceptable and if I make it this way, will I have problems with rejection in App Store?
If you choose to hide & replace the UINavigationBar with your own UIView it's no problem as far as Apple goes.
However, I can tell you that you will have to spend some time trying to replicate some visual effects that come naturally with UINavigationBar.
For example, when you push/pop a new controller, you will see that the navigation bar title will slide & fade beautifully. The same applies for left and right bar items.
Personally I would not completely hide the UINavigationBar, but customize it. In the end it all depends on what you want, but by default the UINavigationBar is pretty customizable.
You can add your own buttons or even entire UIViews as left and right bar items. Also, you can add your own UIView as the title (with your own label, custom font or whatever) or change the background.
EDIT:
To easily customize the looks in your entire application, you can subclass UINavigationController and create your own CustomUINavigationController. Then, in viewDidLoad method you can change whatever you want to the navigation bar and this will be accessible in the entire application.
No way, what you are doing is perfect. This will work & no way it will get rejected from app store (just based on this approach). I too have explored several ways to provide skins & what you wrote seemed to be the least hassle-some. Plus its way more easier to create UI elements in Interface Builder hence the separate nib files for different skins.
I am saying this so confidently 'coz I have done the same thing & app store approved.
Best of luck.
I have a tab bar app that I want to add a banner ad to. I have read another answer about how to add the ad, but it didn't talk about where. It seems the most obvious position would be between the tab bar and my content, but it seems a little disruptive to put the ad between two parts of my interface. I could also put it at the top of the screen, but there are reasons why I don't prefer to do that.
Is there a way I can move the tab bar up to make space for the ad?
Changing the frame of a tabbar controller's view is really painful.
I once considered doing it for some reason and found Adam's answer to Subclass UITabBarController to adjust it's frame very helpful.
But keep in mind that UITabBarController is doing a lot of magic behind (like resizing itself and its view controllers' views at different times) and that it may change with future versions of the OS.
Changing the default behavior of Apple's UI components can also be ground to AppStore rejections (so far I've never seen iAd banners put below the tab bar.)
My goal is to get a navigation bar like the HBO GO app on iPad. Their nav bar has a larger height and a custom background. It seems like they're using a navigation controller since when you press on a show it takes you to a new screen with a back button.
I'm wondering either
1) Can I use an instance of UINavigationBar without a NavigationController and use the navigation bar delegate to handle pushing and popping my views?
or
2)Is there another way that I can implement this?
I am currently trying to do this with a navigation controller and navigation bar but I am running into difficulties and I think its not the best way to do it. Also Apple docs specifically say not to change the frame of the navigation bar in a navcontroller.
Ideas please? Thanks in advance!
From the looks of it, the HBO Go application uses completely custom navigation controls. A basic UINavigationController-alike class is relatively straightforward to build, but you must be careful to consider that UIViewControllers are not intended to be nested on iOS <= 4 and so you will have to pass through several methods such as view{Will,Did}appear:.
I recommend starting from the ground up, as trying to heavily customize the built-in controls will only lead to further frustrations as you run into issues or limitations in their customizability.