I am looking to add a bar with buttons (buttons to fire actions, not for navigation) under the statusBar and above a custom UIView. My question is, I am not sure if I should be using UINavigationBar and adding UIBarButtonItem or if I should be using UIToolBar (which says it is used at the bottom of the screen) again adding UIBarButtonItem for the button?
You would usually use a UINavigationController for this and set the leftBarButtonItem and rightBarButtonItem of the navigationItem property of the view controller for the custom UIView.
Using UIToolbar is probably not what you want since it has a double border at the top, and a less visible border at the bottom, which would look weird in a toolbar at the top of the interface.
Related
I have a view controller that's embedded in a navigation controller. Therefore this view controller has a navigation item at the top. One of the things you can do in ios6 storyboards is that you can set the title, prompt and back button for this view controller (because its embedded in a navigation controller).
That being said, when I specify a title and test the app, everything looks good. However, when I place a transparent UIView on top of the navigation item (such as where the title is), the title itself just vanishes. The text itself that I typed into interface builder is gone. I have proven this because if I delete the view I created, the text I initially had is gone.
I tried to mediate the problem by actually setting the title itself outside of the interface builder:
self.navigationItem.title=#"My Title";
But that doens't seem to work either. Does anyone have a clue as to how I can hide/show a transparent UIView on top of a navigationItem in a navigation controller?
EDIT
Any UI element I place in the navigation controller toolbar seems to prevent the underlying title text from showing up. This happens even if the element is marked as transparent AND its set to hidden.
My understanding is that Interface Builder is, more or less, mimicking what you would do if you did the same thing programmatically using the UIBarButtonItem class. The various items in a navigation bar are instances of the UIBarButtonItem class. This class has the following initializers:
– initWithBarButtonSystemItem:target:action:
– initWithCustomView:
– initWithImage:style:target:action:
– initWithTitle:style:target:action:
– initWithImage:landscapeImagePhone:style:target:action:
When you just have a title for the navigation controller, Interface Builder treats it similar to using the initWithTitle: initializer. Basically, this means that, under the hood, a UILabel class is created with the given title and that UILabel is used as the view for the UIBarButtonItem.
When you are dragging the transparent view over the title, however, Interface Builder is instead doing the equivalent of calling initWithCustomView:. This means that the view you are providing is being used as the UIBarButtonItem's view. In other words, when you drag the custom view over the title, you are not placing it on top of the title. You are replacing the title with the transparent view.
One option might be to create a view which has both a UILabel and the transparent view as subviews. Then place that view as the title for the navigation bar. If you give that UILabel the correct font size and shadow, it will look indistinguishable from the system's default title and you will also be able to have the transparent view on top of it.
In IB, you can drag a UIView to the center of the navigation bar, and this will replace the titleView that is there by default (you can do it in code with setTitleView:). If you make its background clear and add a label to it to hold the title, it will look like the default title. You can then add another UIView as the subview of this view, just like you would with any other UIView.
I'm trying to change a UINavigationController navigation bar to my custom navigation bar (subclass of UINavigationBar) with IB.
So I have a xib file with a UINavigationController, but when I stand on the navigation bar and go to the inspector to change it's class, It shows me a UINavigationItem class not UINavigationBar, and I can't choose my custom navigation bar.
What am I doing wrong?
To answer my own question, I found the solution in this post
Only after I tapped on the "Show Document Outline" button (the rounded arrow at the left bottom), I could find the navigationBar under the navigation controller, and change his class.
I have a navigation bar in my app. I have to have 2 UIBarButtonItems next to each other, which i have put in a UIToolbar, and that UIToolbar is assigned as the rightBarButtonItem of my view controller like:
self.navigationItem.rightBarButtonItem = rightToolbarButtonItem
where the rightToolbarButtonItem is a toolbar, in turn having 2 buttons. Now, on clicking any of the bar buttons, i have to show a UIPopoverController. So i use:
presentPopoverFromBarButtonItem: permittedArrowDirections: animated:
But, in both cases, my popover arrow direction is the same. because it is taking the whole toolbar as a buttonItem. I want to show the arrow direction according to the bar button items in the toolbar.
Is there a way out?
I made it work by presenting the popover from rect instead of presenting it from barButtonItem and hardcoded the rects for both the barButtonItems.
I have a navigationController which has a navigation bar. I would really like to have 3 UIBarButtonItems, one on the left, one in the middle, and one on the right. I am able to get the left and right ones added, but how would I add one in the middle, since when using a navigationController, I can't add an array of items to the navBar items property?
Could I somehow add a UIButton, styled like a UIBarButtonItem in the titleView location?
taken from apple api, basically you can create a custom UIView that has a UIButton in it and use this as your titleView (notice the note about a leftBarButtonItem causes the titleView to be ignored and not shown): (edit note: this is a property of UINavigationItem)
titleView
A custom view displayed in the center of the navigation bar when this item is the top item.
#property(nonatomic, retain) UIView *titleView
Discussion
If this property value is nil, the navigation item’s title is displayed in the center of the navigation bar when this item is the top item. If you set this property to a custom title, it is displayed instead of the title. This property is ignored if leftBarButtonItem is not nil.
Custom views can contain buttons. Use the buttonWithType: method in UIButton class to add buttons to your custom view in the style of the navigation bar. Custom title views are centered on the navigation bar and may be resized to fit.
I like the look of the UIBarButtonItem buttons. Is there a way to put these on a screen without using a UINavigationBar or UIToolbar.. so the button are just placed straight onto a view? (or possibly put them onto on nav bar or toolbar whose content is invisible, except for the bar buttons)
As they do not inherit from UIView and don't expose a view property (except for those customView based ones), you cannot simply add them onto views out of the box. Also, they might need to "talk back" to their bar container, which would fail anyway. Go with UIButton with custom image.
You cant use Bar button directly on button if you like those button then you can pick the image for same and use that with the round rect or custom button.