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.
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.
It only allows me to add the right barbutton, but when I drag another barbuttonitem, it's simply denied.
I looked at the properties of NavigationItem, and I saw that there are outlets for right barbutton and even for the back barbutton.
So: why can't I add a left barbutton item to the Navigation Item (through Interface Builder)?
Yeah, using it programatically is probably (way) better.
Use [self.navigationController pushViewController:<otherviewname> animated:YES];
This way, in the next view, there is a backbutton to this screen added automatically (unless you decide to hide the backbutton programatically in that next view, but that's a whole different story).
The advantage of pushViewController instead of modalTransitionView is that navigation-options are so easily added!
It seems that you cannot add a button to a Navigation Bar if it is defined in the View properties, however if you add a Navigation Bar from the Object Library you can add buttons (left and right).
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.
How can I add image and text together in an iPhone Navigation bar?
From a view controller, you can ask for self.navigationController.navigationBar and add subviews to that.
Or, you can wrap image/text into a UIView, and create a UIBarButtonItem with a custom view set to that combination.
For my answer, I'm assuming you want to show an image in the NavBar with the text prompt above it - in which case, you'd be looking to use the prompt property on the UINavigationItem class.
As titled. I need a way to display the arrow buttom on UINavigationbar without actually pushing a controller. The reason why I can't push a controller is because I need to keep the keyboard displayed while transitioning.
So to clarify: I start with a modal view controller (where there's nothing on the top left bar) like this -
(source: iphonefaq.org)
Then transition the top bar to one that looks like this -
(source: gizmodo.com)
Sure, you can do this pretty easily. Just set the leftBarButtonItem of your self.navigationItem to be a back button.
It looks like you can do this by getting the UINavigationItem for the current screen. You can get it from the topItem property of the UINavigationBar.
Once you have the UINavigationItem that represents your current title are you should be able to experiment with the backBarButtonItem property, then call setHidesBackButton:animated: to show the back button.
You can*not* dynamically change the backbutton on the UINavigationItem instance that belongs to the UIViewController instance that is currently being displayed. The backbutton that you will see displayed is the last one that was set before the UIViewController instance (and its UINAvigationItem) was pushed.
BUT, you can show/hide the backbutton. So how about setting the correct backbutton before the UIViewController instance is pushed and hiding it (viewControllerInstance.navigationItem.hidesBackButton = YES;"). And then setting "viewControllerInstance.navigationItem.hidesBackButton = NO;" when you want to display the back button.
You can obviously dynamically change the UINavigationItems and their backbuttons on a UINavigationBar that you create yourself (i.e. one that does not belong to a UINavigationController).